-
Notifications
You must be signed in to change notification settings - Fork 727
feat: integration service sync to repositories [CM-865] #3722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
4 similar comments
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
| }), | ||
| }, | ||
| segmentOptions, | ||
| PlatformType.GITHUB, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing repository sync for GitHub and GitLab integrations
The PR adds PlatformType.GITHUB and PlatformType.GITLAB parameters to gitConnectOrUpdate calls, which causes the internal mapUnifiedRepositories call to be skipped (due to the if (!sourcePlatform) check at line 1422). However, unlike githubNangoConnect (which adds an external call at line 961) and gerritConnectOrUpdate (which adds an external call at line 1789), neither mapGithubRepos nor mapGitlabRepos add the required external mapUnifiedRepositories call. This means when these methods are called directly via API endpoints (githubMapRepos.ts, gitlabMapRepos.ts) or from updateGithubIntegrationSettings, repositories won't be synced to public.repositories, breaking the PR's stated goal of consistent repository mapping across all platforms.
Additional Locations (1)
|
|
||
| const txOptions = { ...this.options, transaction } | ||
| const txService = new IntegrationService(txOptions) | ||
| await txService.mapUnifiedRepositories(PlatformType.GERRIT, integration.id, mapping) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gerrit repository sync fails when Git disabled
The mapUnifiedRepositories call for Gerrit is placed outside the if (integrationData.remote.enableGit) block, meaning it executes unconditionally. However, buildRepositoryPayloads requires a Git integration to exist - it calls IntegrationRepository.findByPlatform(PlatformType.GIT, ...) and throws Error400 if not found. When enableGit is false, no Git integration is created by gitConnectOrUpdate, so the subsequent mapUnifiedRepositories call will fail with "Git integration not found for segment". The mapUnifiedRepositories call should be inside the if (enableGit) block.
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
| const [gitRepoIdMap, sourceIntegration] = await Promise.all([ | ||
| // TODO: after migration, generate UUIDs instead of fetching from git.repositories | ||
| getGitRepositoryIdsByUrl(qx, urls), | ||
| isGitHubPlatform ? IntegrationRepository.findById(sourceIntegrationId, txOptions) : null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitLab forkedFrom data not synced to public.repositories
In buildRepositoryPayloads, the sourceIntegration is only fetched for GitHub platforms (line 3118 uses a conditional that returns null for non-GitHub). The forkedFromMap at lines 3157-3166 is populated exclusively from sourceIntegration?.settings?.orgs, which is GitHub-specific. For GitLab repositories, forkedFromMap remains empty, causing all GitLab repos to have forkedFrom: null in public.repositories. However, GitLab's forkedFrom data IS available and passed to gitConnectOrUpdate (lines 2873-2875, 2884-2886), so the information exists but isn't propagated to the unified repositories table.
Additional Locations (1)
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
1 similar comment
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
| remotes: repositories.map((url) => ({ url, forkedFrom: null })), | ||
| }, | ||
| txOptions, | ||
| platform, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing repository sync in integration update method
The update method now passes platform to gitConnectOrUpdate which skips the internal mapUnifiedRepositories call. However, the update method doesn't add its own mapUnifiedRepositories call afterward. This creates a regression where updating code platform integrations syncs to git.repositories but no longer syncs to public.repositories, breaking the unified repository table consistency.
| const gitIntegration = await IntegrationRepository.findByPlatform( | ||
| PlatformType.GIT, | ||
| segmentOptions, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integration destroy fails without Git integration
The call to IntegrationRepository.findByPlatform at line 433 lacks error handling. The original code wrapped this in a try-catch with shouldUpdateGit fallback to gracefully handle missing Git integrations. The new code assumes a Git integration always exists for GitHub/GitLab integrations. If a Git integration is missing (due to partial creation failures, manual deletion, or legacy data), findByPlatform throws an error, causing the entire destroy operation to fail and roll back instead of proceeding with cleanup.
| SELECT id, url FROM gitlab_repos | ||
| UNION ALL | ||
| SELECT id, url FROM git_repos | ||
| ) combined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DISTINCT ON query without ORDER BY is non-deterministic
The SQL query in syncRepositoriesToGitV2 uses DISTINCT ON (url) without a corresponding ORDER BY clause. When the same URL exists in multiple source tables (github_repos, gitlab_repos, git_repos) with potentially different IDs, PostgreSQL will return an arbitrary row. This could lead to inconsistent repository ID selection across different executions, though in practice this may only manifest if there's existing data inconsistency between the tables.
8f348bc to
be61340
Compare
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
1 similar comment
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
644a90c to
442550f
Compare
This pull request introduces significant improvements to the repository integration and synchronization logic within the
IntegrationServiceinbackend/src/services/integrationService.ts. The main focus is on ensuring that repository mappings between source integrations and the unifiedpublic.repositoriestable are consistent, robust, and transactional across different platforms (GitHub, GitLab, Gerrit, and direct Git). The changes add validation, transactional safety, and better handling of edge cases when mapping, restoring, or soft-deleting repositories.Key changes include:
Repository Mapping and Synchronization Enhancements
mapUnifiedRepositories, which handles inserting, restoring, and soft-deleting repositories in the unifiedpublic.repositoriestable in a transactional manner. This includes robust validation to prevent remapping repositories across different integrations and ensures consistency across platforms.validateRepoIntegrationMappingandbuildRepositoryPayloadsto support the main mapping logic, including building payloads with correct associations (segment, integration, insights project, forkedFrom, etc.).Platform-Aware Repository Synchronization
gitConnectOrUpdatemethod and all relevant integration flows (GitHub, GitLab, Gerrit, direct Git) to callmapUnifiedRepositorieswith the correct platform and integration context, ensuring that repository synchronization is handled appropriately for each platform. [1] [2] [3]sourcePlatformparameter togitConnectOrUpdateto control when unified repository mapping should be triggered, allowing for more flexible integration flows.Integration with Data Access Layer
Improved Transaction Management
Platform-Specific Handling in Integration Flows
These changes make the repository integration process more reliable, maintainable, and scalable across different source platforms.
Note
Introduces a unified repository-mapping flow across code platforms (GitHub, GitLab, Gerrit, Git) backed by
public.repositories, plus a single API to fetch mappings.GET /integration/:id/repositoriesand removes platform-specific repo GETs; frontend now usesIntegrationService.fetchIntegrationRepositoriesfor GitHub, GitLab, and GitIntegrationServicerefactor: newmapUnifiedRepositories(insert/restore/soft-delete with validations and mirrored-repo handling),getIntegrationRepositories, and enhanced deletion logic to preserve/clean up repos correctly;gitConnectOrUpdategainssourcePlatformand syncs only owned reposrepositoriesmodule (insertRepositories,restoreRepositories,softDeleteRepositories,getRepositoriesBy*,getIntegrationReposMapping), andsyncRepositoriesToGitV2now reuses IDs from github/gitlab/git where availablearray-inputsupportsdisabled; Gerrit UI defaultsenableGitto true and hides the toggleWritten by Cursor Bugbot for commit 442550f. This will update automatically on new commits. Configure here.