diff --git a/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts b/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts index cc86801bf1..949d96e406 100644 --- a/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts +++ b/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts @@ -6,6 +6,23 @@ import { Repos } from '../../../types/regularTypes' const log = getServiceChildLogger('getInstalledRepositories') +/** + * Normalizes forkedFrom URL for special cases. + */ +const normalizeForkedFrom = (forkedFrom: string | null): string | null => { + if (!forkedFrom) { + return null + } + + // Special case: Linux kernel on GitHub should map to the official kernel.org git repository + // because that's the one onboarded in our system, not the GitHub mirror. + if (forkedFrom.endsWith('github.com/torvalds/linux')) { + return 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux' + } + + return forkedFrom +} + const getRepositoriesFromGH = async (page: number, installToken: string): Promise => { const REPOS_PER_PAGE = 100 @@ -33,7 +50,7 @@ const parseRepos = (repositories: any): Repos => { fork: repo.fork, private: repo.private, cloneUrl: repo.clone_url, - forkedFrom: repo.parent?.html_url || null, + forkedFrom: normalizeForkedFrom(repo.parent?.html_url || null), }) } diff --git a/backend/src/services/githubIntegrationService.ts b/backend/src/services/githubIntegrationService.ts index 11d3cabb1d..caaf076a76 100644 --- a/backend/src/services/githubIntegrationService.ts +++ b/backend/src/services/githubIntegrationService.ts @@ -16,6 +16,23 @@ const githubMaxSearchResult = 1000 export default class GithubIntegrationService { constructor(private readonly options: IServiceOptions) {} + /** + * Normalizes forkedFrom URL for special cases. + */ + private static normalizeForkedFrom(forkedFrom: string | null): string | null { + if (!forkedFrom) { + return null + } + + // Special case: Linux kernel on GitHub should map to the official kernel.org git repository + // because that's the one onboarded in our system, not the GitHub mirror. + if (forkedFrom.endsWith('github.com/torvalds/linux')) { + return 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux' + } + + return forkedFrom + } + /** * Fetches the parent repository information for a forked repository * @param owner - The owner of the repository @@ -32,7 +49,7 @@ export default class GithubIntegrationService { }) if (data && data.parent) { - return data.parent.html_url + return GithubIntegrationService.normalizeForkedFrom(data.parent.html_url) } } catch (error) { const logger = getServiceLogger() @@ -221,7 +238,7 @@ export default class GithubIntegrationService { // Get forked_from if the repo is a fork let forkedFrom = null if (data.fork && data.parent) { - forkedFrom = data.parent.html_url + forkedFrom = GithubIntegrationService.normalizeForkedFrom(data.parent.html_url) } return {