@@ -28,7 +28,11 @@ import {
2828 restoreRepositories ,
2929 softDeleteRepositories ,
3030} from '@crowd/data-access-layer/src/repositories'
31- import { getGithubMappedRepos , getGitlabMappedRepos } from '@crowd/data-access-layer/src/segments'
31+ import {
32+ getMappedRepos ,
33+ getMappedWithSegmentName ,
34+ hasMappedRepos ,
35+ } from '@crowd/data-access-layer/src/segments'
3236import {
3337 NangoIntegration ,
3438 connectNangoIntegration ,
@@ -1146,25 +1150,6 @@ export default class IntegrationService {
11461150 }
11471151 }
11481152
1149- async getGithubRepos ( integrationId ) : Promise < any [ ] > {
1150- const transaction = await SequelizeRepository . createTransaction ( this . options )
1151-
1152- const txOptions = {
1153- ...this . options ,
1154- transaction,
1155- }
1156-
1157- try {
1158- const mapping = await GithubReposRepository . getMapping ( integrationId , txOptions )
1159-
1160- await SequelizeRepository . commitTransaction ( transaction )
1161- return mapping
1162- } catch ( err ) {
1163- await SequelizeRepository . rollbackTransaction ( transaction )
1164- throw err
1165- }
1166- }
1167-
11681153 /**
11691154 * Get repository mappings for an integration
11701155 * Uses the unified public.repositories table instead of legacy githubRepos table
@@ -2638,8 +2623,9 @@ export default class IntegrationService {
26382623 updatedAt : string
26392624 } [ ]
26402625
2641- const githubRepos = await this . getGithubRepos ( integrationId )
2642- const mappedSegments = githubRepos . map ( ( repo ) => repo . segment . id )
2626+ const qx = SequelizeRepository . getQueryExecutor ( this . options )
2627+ const githubRepos = await getRepositoriesBySourceIntegrationId ( qx , integrationId )
2628+ const mappedSegments = githubRepos . map ( ( repo ) => repo . segmentId )
26432629
26442630 const cacheRemote = new RedisCache (
26452631 'github-progress-remote' ,
@@ -2858,22 +2844,25 @@ export default class IntegrationService {
28582844 }
28592845
28602846 async getIntegrationMappedRepos ( segmentId : string ) {
2861- const segmentRepository = new SegmentRepository ( this . options )
2862- const hasMappedRepos = await segmentRepository . hasMappedRepos ( segmentId )
2847+ const qx = SequelizeRepository . getQueryExecutor ( this . options )
2848+ const githubPlatforms = [ PlatformType . GITHUB , PlatformType . GITHUB_NANGO ]
2849+
2850+ const hasRepos = await hasMappedRepos ( qx , segmentId , githubPlatforms )
28632851
2864- if ( ! hasMappedRepos ) {
2852+ if ( ! hasRepos ) {
28652853 return null
28662854 }
28672855
2868- const qx = SequelizeRepository . getQueryExecutor ( this . options )
2869-
2870- const gitlabMappedRepos = await getGitlabMappedRepos ( qx , segmentId )
2871- const githubMappedRepos = await getGithubMappedRepos ( qx , segmentId )
2872- const project = await segmentRepository . mappedWith ( segmentId )
2856+ const [ githubMappedRepos , githubNangoMappedRepos , gitlabMappedRepos ] = await Promise . all ( [
2857+ getMappedRepos ( qx , segmentId , PlatformType . GITHUB ) ,
2858+ getMappedRepos ( qx , segmentId , PlatformType . GITHUB_NANGO ) ,
2859+ getMappedRepos ( qx , segmentId , PlatformType . GITLAB ) ,
2860+ ] )
2861+ const project = await getMappedWithSegmentName ( qx , segmentId , githubPlatforms )
28732862
28742863 return {
28752864 project,
2876- repositories : [ ...githubMappedRepos , ...gitlabMappedRepos ] ,
2865+ repositories : [ ...githubMappedRepos , ...githubNangoMappedRepos , ... gitlabMappedRepos ] ,
28772866 }
28782867 }
28792868
@@ -3077,25 +3066,6 @@ export default class IntegrationService {
30773066 }
30783067 }
30793068
3080- async getGitlabRepos ( integrationId ) : Promise < any [ ] > {
3081- const transaction = await SequelizeRepository . createTransaction ( this . options )
3082-
3083- const txOptions = {
3084- ...this . options ,
3085- transaction,
3086- }
3087-
3088- try {
3089- const mapping = await GitlabReposRepository . getMapping ( integrationId , txOptions )
3090-
3091- await SequelizeRepository . commitTransaction ( transaction )
3092- return mapping
3093- } catch ( err ) {
3094- await SequelizeRepository . rollbackTransaction ( transaction )
3095- throw err
3096- }
3097- }
3098-
30993069 async updateGithubIntegrationSettings ( installId : string ) {
31003070 this . options . log . info ( `Updating GitHub integration settings for installId: ${ installId } ` )
31013071
0 commit comments