Skip to content

Commit ab434fb

Browse files
authored
fix(git-integration): sync repos to git v2 (#3546)
1 parent 1afd74c commit ab434fb

2 files changed

Lines changed: 28 additions & 35 deletions

File tree

backend/src/database/repositories/gitReposRepository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export default class GitReposRepository {
8080
"integrationId" = EXCLUDED."integrationId",
8181
"segmentId" = EXCLUDED."segmentId",
8282
"forkedFrom" = COALESCE(EXCLUDED."forkedFrom", git.repositories."forkedFrom"),
83-
"updatedAt" = NOW()
83+
"updatedAt" = NOW(),
84+
"deletedAt" = EXCLUDED."deletedAt"
8485
`,
8586
{
8687
replacements,

backend/src/services/integrationService.ts

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,6 @@ export default class IntegrationService {
13401340
options || this.options,
13411341
transaction,
13421342
integration.id,
1343-
// 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
13441343
)
13451344

13461345
// Only commit if we created the transaction ourselves
@@ -1376,7 +1375,6 @@ export default class IntegrationService {
13761375
options: IRepositoryOptions,
13771376
transaction: Transaction,
13781377
integrationId: string,
1379-
inheritFromExistingRepos: boolean = true,
13801378
) {
13811379
const seq = SequelizeRepository.getSequelize(options)
13821380

@@ -1387,14 +1385,12 @@ export default class IntegrationService {
13871385
segmentId: string
13881386
forkedFrom?: string | null
13891387
}> = []
1390-
1391-
if (inheritFromExistingRepos) {
1392-
// check GitHub repos first, fallback to GitLab repos if none found
1393-
const existingRepos: Array<{
1394-
id: string
1395-
url: string
1396-
}> = await seq.query(
1397-
`
1388+
// check GitHub repos first, fallback to GitLab repos if none found
1389+
const existingRepos: Array<{
1390+
id: string
1391+
url: string
1392+
}> = await seq.query(
1393+
`
13981394
WITH github_repos AS (
13991395
SELECT id, url FROM "githubRepos"
14001396
WHERE url IN (:urls) AND "deletedAt" IS NULL
@@ -1408,34 +1404,30 @@ export default class IntegrationService {
14081404
SELECT id, url FROM gitlab_repos
14091405
WHERE NOT EXISTS (SELECT 1 FROM github_repos)
14101406
`,
1411-
{
1412-
replacements: {
1413-
urls: remotes.map((r) => r.url),
1414-
},
1415-
type: QueryTypes.SELECT,
1416-
transaction,
1407+
{
1408+
replacements: {
1409+
urls: remotes.map((r) => r.url),
14171410
},
1418-
)
1411+
type: QueryTypes.SELECT,
1412+
transaction,
1413+
},
1414+
)
14191415

1420-
// Create a map of url to forkedFrom for quick lookup
1421-
const forkedFromMap = new Map(remotes.map((r) => [r.url, r.forkedFrom]))
1416+
// Create a map of url to forkedFrom for quick lookup
1417+
const forkedFromMap = new Map(remotes.map((r) => [r.url, r.forkedFrom]))
14221418

1423-
repositoriesToSync = existingRepos.map((repo) => ({
1424-
id: repo.id,
1425-
url: repo.url,
1426-
integrationId,
1427-
segmentId: options.currentSegments[0].id,
1428-
forkedFrom: forkedFromMap.get(repo.url) || null,
1429-
}))
1419+
repositoriesToSync = existingRepos.map((repo) => ({
1420+
id: repo.id,
1421+
url: repo.url,
1422+
integrationId,
1423+
segmentId: options.currentSegments[0].id,
1424+
forkedFrom: forkedFromMap.get(repo.url) || null,
1425+
}))
14301426

1431-
if (repositoriesToSync.length === 0) {
1432-
this.options.log.warn(
1433-
'No existing repos found in githubRepos or gitlabRepos - skipping repository sync to git v2',
1434-
)
1435-
return
1436-
}
1437-
} else {
1438-
// Generate new entries with auto-generated UUIDs
1427+
if (repositoriesToSync.length === 0) {
1428+
this.options.log.warn(
1429+
'No existing repos found in githubRepos or gitlabRepos - inserting new to git.repositories with new uuid',
1430+
)
14391431
repositoriesToSync = remotes.map((remote) => ({
14401432
id: uuidv4(), // Generate new UUID
14411433
url: remote.url,

0 commit comments

Comments
 (0)