Skip to content

Commit fa51fde

Browse files
committed
repo add fix
1 parent 89d7d62 commit fa51fde

2 files changed

Lines changed: 44 additions & 45 deletions

File tree

service/src/app-models/stacks/actions/import-stack-action.ts

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,55 @@ export const ImportStackAction: RequestAction<ImportStackEndpoint> = async ({ in
1515

1616
await logger.information({ message: `Importing stack: ${stackName}` })
1717

18-
const addedRepoIds: string[] = []
19-
const addedDepIds: string[] = []
20-
const addedServiceIds: string[] = []
18+
const repositories = body.repositories.map((repo) => ({
19+
...repo,
20+
stackName,
21+
createdAt: now,
22+
updatedAt: now,
23+
}))
2124

22-
try {
23-
const stackStore = sm.getStoreFor(Stack, 'name')
24-
await stackStore.add({ ...body.stack, createdAt: now, updatedAt: now })
25-
26-
const repoStore = sm.getStoreFor(GitHubRepository, 'id')
27-
for (const repo of body.repositories) {
28-
await repoStore.add({ ...repo, stackName, createdAt: now, updatedAt: now })
29-
addedRepoIds.push(repo.id)
30-
}
25+
const dependencies = body.dependencies.map((dep) => ({
26+
...dep,
27+
stackName,
28+
createdAt: now,
29+
updatedAt: now,
30+
}))
3131

32-
const depStore = sm.getStoreFor(Dependency, 'id')
33-
for (const dep of body.dependencies) {
34-
await depStore.add({ ...dep, stackName, createdAt: now, updatedAt: now })
35-
addedDepIds.push(dep.id)
36-
}
32+
const services = body.services.map((svc) => ({
33+
...svc,
34+
stackName,
35+
installStatus: 'not-installed' as const,
36+
buildStatus: 'not-built' as const,
37+
runStatus: 'stopped' as const,
38+
createdAt: now,
39+
updatedAt: now,
40+
}))
3741

38-
const serviceStore = sm.getStoreFor(Service, 'id')
39-
for (const svc of body.services) {
40-
await serviceStore.add({
41-
...svc,
42-
stackName,
43-
installStatus: 'not-installed',
44-
buildStatus: 'not-built',
45-
runStatus: 'stopped',
46-
createdAt: now,
47-
updatedAt: now,
48-
})
49-
addedServiceIds.push(svc.id)
50-
}
42+
try {
43+
await sm.getStoreFor(Stack, 'name').add({ ...body.stack, createdAt: now, updatedAt: now })
44+
await sm.getStoreFor(GitHubRepository, 'id').add(...repositories)
45+
await sm.getStoreFor(Dependency, 'id').add(...dependencies)
46+
await sm.getStoreFor(Service, 'id').add(...services)
5147
} catch (error) {
5248
await logger.warning({ message: `Import failed for stack ${stackName}, rolling back`, data: { error } })
5349

54-
for (const id of addedServiceIds) {
55-
await sm.getStoreFor(Service, 'id').remove(id).catch(() => {})
50+
for (const svc of services) {
51+
await sm
52+
.getStoreFor(Service, 'id')
53+
.remove(svc.id)
54+
.catch(() => {})
5655
}
57-
for (const id of addedDepIds) {
58-
await sm.getStoreFor(Dependency, 'id').remove(id).catch(() => {})
56+
for (const dep of dependencies) {
57+
await sm
58+
.getStoreFor(Dependency, 'id')
59+
.remove(dep.id)
60+
.catch(() => {})
5961
}
60-
for (const id of addedRepoIds) {
61-
await sm.getStoreFor(GitHubRepository, 'id').remove(id).catch(() => {})
62+
for (const repo of repositories) {
63+
await sm
64+
.getStoreFor(GitHubRepository, 'id')
65+
.remove(repo.id)
66+
.catch(() => {})
6267
}
6368
await sm
6469
.getStoreFor(Stack, 'name')

service/src/services/process-manager.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,13 @@ export class ProcessManager {
179179
purpose: 'install' | 'build',
180180
): Promise<void> {
181181
const progressStatus =
182-
purpose === 'install'
183-
? ({ installStatus: 'installing' } as const)
184-
: ({ buildStatus: 'building' } as const)
182+
purpose === 'install' ? ({ installStatus: 'installing' } as const) : ({ buildStatus: 'building' } as const)
185183

186184
const doneStatus =
187-
purpose === 'install'
188-
? ({ installStatus: 'installed' } as const)
189-
: ({ buildStatus: 'built' } as const)
185+
purpose === 'install' ? ({ installStatus: 'installed' } as const) : ({ buildStatus: 'built' } as const)
190186

191187
const failedStatus =
192-
purpose === 'install'
193-
? ({ installStatus: 'failed' } as const)
194-
: ({ buildStatus: 'failed' } as const)
188+
purpose === 'install' ? ({ installStatus: 'failed' } as const) : ({ buildStatus: 'failed' } as const)
195189

196190
await this.updateServiceStatus(serviceId, progressStatus)
197191

0 commit comments

Comments
 (0)