Skip to content

Commit bdd6d66

Browse files
Clean up invalid installation ids (#9704)
Signed-off-by: Artem Savchenko <[email protected]>
1 parent 486fa40 commit bdd6d66

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

dev/tool/src/restoreGithub.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export async function restoreGithubIntegrations (dbUrl: string, dryrun: boolean)
5757
const allInstallationIds = new Set<number>()
5858
if (existingInstallationId != null) {
5959
if (Array.isArray(existingInstallationId)) {
60-
existingInstallationId.forEach((id) => allInstallationIds.add(id))
61-
} else {
60+
existingInstallationId.filter(isValidInstallationId).forEach((id) => allInstallationIds.add(id))
61+
} else if (isValidInstallationId(existingInstallationId)) {
6262
allInstallationIds.add(existingInstallationId)
6363
}
6464
}
@@ -91,6 +91,7 @@ export async function restoreGithubIntegrations (dbUrl: string, dryrun: boolean)
9191
}
9292
if (dryrun) {
9393
console.info('Dry run: would update integration', existingIntegration, updatedIntegration)
94+
updatedCount++
9495
continue
9596
}
9697
await accountClient.updateIntegration(updatedIntegration)
@@ -107,6 +108,7 @@ export async function restoreGithubIntegrations (dbUrl: string, dryrun: boolean)
107108
}
108109
if (dryrun) {
109110
console.info('Dry run: would create integration', integration)
111+
createdCount++
110112
continue
111113
}
112114
await accountClient.createIntegration(integration)
@@ -148,3 +150,11 @@ function groupIntegrationSettings (
148150

149151
return Array.from(groupedSettings.values())
150152
}
153+
154+
function isValidInstallationId (id: any): boolean {
155+
if (typeof id === 'number' && !isNaN(id) && id > 0) {
156+
return true
157+
}
158+
const parsed = parseInt(String(id), 10)
159+
return !isNaN(parsed) && parsed > 0
160+
}

0 commit comments

Comments
 (0)