@@ -902,13 +902,15 @@ export default class IntegrationService {
902902 }
903903
904904 async mapGithubRepos ( integrationId , mapping , fireOnboarding = true ) {
905+ this . options . log . info ( `Mapping GitHub repos for integration ${ integrationId } !` )
905906 const transaction = await SequelizeRepository . createTransaction ( this . options )
906907
907908 const txOptions = {
908909 ...this . options ,
909910 transaction,
910911 }
911912 try {
913+ this . options . log . info ( `Updating GitHub repos mapping for integration ${ integrationId } !` )
912914 await GithubReposRepository . updateMapping ( integrationId , mapping , txOptions )
913915
914916 // add the repos to the git integration
@@ -927,9 +929,11 @@ export default class IntegrationService {
927929 const collectionService = new CollectionService ( txOptions )
928930
929931 for ( const [ segmentId , repositories ] of Object . entries ( repos ) ) {
932+ this . options . log . info ( `Finding insights project for segment ${ segmentId } !` )
930933 const [ insightsProject ] = await collectionService . findInsightsProjectsBySegmentId ( segmentId )
931934
932935 if ( insightsProject ) {
936+ this . options . log . info ( `Upserting segment repositories for segment ${ segmentId } !` )
933937 await upsertSegmentRepositories ( qx , {
934938 insightsProjectId : insightsProject . id ,
935939 repositories,
@@ -945,7 +949,7 @@ export default class IntegrationService {
945949 for ( const [ segmentId , urls ] of Object . entries ( repos ) ) {
946950 let isGitintegrationConfigured
947951 const segmentOptions : IRepositoryOptions = {
948- ...this . options ,
952+ ...txOptions ,
949953 currentSegments : [
950954 {
951955 ...this . options . currentSegments [ 0 ] ,
@@ -954,6 +958,7 @@ export default class IntegrationService {
954958 ] ,
955959 }
956960 try {
961+ this . options . log . info ( `Finding Git integration for segment ${ segmentId } !` )
957962 await IntegrationRepository . findByPlatform ( PlatformType . GIT , segmentOptions )
958963
959964 isGitintegrationConfigured = true
@@ -962,15 +967,18 @@ export default class IntegrationService {
962967 }
963968
964969 if ( isGitintegrationConfigured ) {
970+ this . options . log . info ( `Finding Git integration for segment ${ segmentId } !` )
965971 const gitInfo = await this . gitGetRemotes ( segmentOptions )
966972 const gitRemotes = gitInfo [ segmentId as string ] . remotes
973+ this . options . log . info ( `Updating Git integration for segment ${ segmentId } !` )
967974 await this . gitConnectOrUpdate (
968975 {
969976 remotes : Array . from ( new Set ( [ ...gitRemotes , ...urls ] ) ) ,
970977 } ,
971978 segmentOptions ,
972979 )
973980 } else {
981+ this . options . log . info ( `Updating Git integration for segment ${ segmentId } !` )
974982 await this . gitConnectOrUpdate (
975983 {
976984 remotes : urls ,
@@ -981,6 +989,7 @@ export default class IntegrationService {
981989 }
982990
983991 if ( fireOnboarding ) {
992+ this . options . log . info ( 'Updating integration status to in-progress!' )
984993 const integration = await IntegrationRepository . update (
985994 integrationId ,
986995 { status : 'in-progress' } ,
@@ -994,7 +1003,12 @@ export default class IntegrationService {
9941003
9951004 await SequelizeRepository . commitTransaction ( transaction )
9961005 } catch ( err ) {
997- await SequelizeRepository . rollbackTransaction ( transaction )
1006+ this . options . log . error ( err , 'Error while mapping GitHub repos!' )
1007+ try {
1008+ await SequelizeRepository . rollbackTransaction ( transaction )
1009+ } catch ( rErr ) {
1010+ this . options . log . error ( rErr , 'Error while rolling back transaction!' )
1011+ }
9981012 throw err
9991013 }
10001014 }
@@ -1266,7 +1280,9 @@ export default class IntegrationService {
12661280 return null
12671281 }
12681282
1269- const transaction = await SequelizeRepository . createTransaction ( options || this . options )
1283+ const existingTransaction = SequelizeRepository . getTransaction ( options || this . options )
1284+ const transaction =
1285+ existingTransaction || ( await SequelizeRepository . createTransaction ( options || this . options ) )
12701286 let integration
12711287
12721288 try {
@@ -1291,9 +1307,15 @@ export default class IntegrationService {
12911307 // inheritFromExistingRepos defaults to true during migration until all repos are migrated then git.repositories can be used as source of truth instead of existing repo tables
12921308 )
12931309
1294- await SequelizeRepository . commitTransaction ( transaction )
1310+ // Only commit if we created the transaction ourselves
1311+ if ( ! existingTransaction ) {
1312+ await SequelizeRepository . commitTransaction ( transaction )
1313+ }
12951314 } catch ( err ) {
1296- await SequelizeRepository . rollbackTransaction ( transaction )
1315+ // Only rollback if we created the transaction ourselves
1316+ if ( ! existingTransaction ) {
1317+ await SequelizeRepository . rollbackTransaction ( transaction )
1318+ }
12971319 this . options . log . error ( `gitConnectOrUpdate failed with error: ${ err } ` )
12981320 throw err
12991321 }
0 commit comments