Skip to content

Commit 304dd20

Browse files
joanagmaiaCopilot
andauthored
fix: projects metadata on github nango (#3918)
Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 255fd66 commit 304dd20

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

backend/src/services/integrationService.ts

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,17 @@ export default class IntegrationService {
195195
const { segmentId, id: insightsProjectId } = insightsProject
196196
const { platform } = data
197197

198-
await this.updateInsightsProject({
199-
insightsProjectId,
200-
isFirstUpdate: true,
201-
platform,
202-
segmentId,
203-
transaction,
204-
})
198+
// Skip for GITHUB_NANGO: repos aren't available at create time.
199+
// - GITHUB_NANGO: repos stripped from settings; githubNangoConnect calls updateInsightsProject after mapGithubRepos populates public.repositories.
200+
if (platform !== PlatformType.GITHUB_NANGO) {
201+
await this.updateInsightsProject({
202+
insightsProjectId,
203+
isFirstUpdate: true,
204+
platform,
205+
segmentId,
206+
transaction,
207+
})
208+
}
205209

206210
return integration
207211
} catch (error) {
@@ -836,6 +840,36 @@ export default class IntegrationService {
836840

837841
// create github mapping - this also creates git integration
838842
await txService.mapGithubRepos(integration.id, mapping, false, forkedFromMap)
843+
844+
// Re-run updateInsightsProject now that repos are mapped, so metadata can be fetched.
845+
// This is a best-effort enrichment step: failures here should not roll back the core
846+
// GitHub Nango connection or repo mapping.
847+
try {
848+
const collectionService = new CollectionService(txOptions)
849+
const [insightsProject] = await collectionService.findInsightsProjectsBySegmentId(
850+
integration.segmentId,
851+
)
852+
if (insightsProject) {
853+
await txService.updateInsightsProject({
854+
insightsProjectId: insightsProject.id,
855+
isFirstUpdate: true,
856+
platform: PlatformType.GITHUB_NANGO,
857+
segmentId: insightsProject.segmentId,
858+
transaction,
859+
})
860+
}
861+
} catch (err) {
862+
// Log and continue; metadata enrichment is non-critical and should not block connection.
863+
// eslint-disable-next-line no-console
864+
console.error(
865+
'Failed to update insights project metadata after GitHub Nango connection',
866+
{
867+
integrationId: integration?.id,
868+
segmentId: integration?.segmentId,
869+
error: err,
870+
},
871+
)
872+
}
839873
} else {
840874
// update existing integration
841875
integration = await txService.findById(integrationId)

0 commit comments

Comments
 (0)