From 2f9e27530cfc2fc5cc00029d3aa869bdef7a97cb Mon Sep 17 00:00:00 2001 From: Mouad BANI Date: Tue, 28 Oct 2025 15:26:29 +0100 Subject: [PATCH 1/2] fix: use git url instead of github mirror for kernel repo --- .../github/rest/getInstalledRepositories.ts | 19 ++++++++++++++++- .../src/services/githubIntegrationService.ts | 21 +++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts b/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts index cc86801bf1..d516bc940c 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 === 'https://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..8e7c99b2ae 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 === 'https://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 { From b1b08b8f7fdc6d2122abf08597ef8994f8adc134 Mon Sep 17 00:00:00 2001 From: Mouad BANI Date: Tue, 28 Oct 2025 15:31:54 +0100 Subject: [PATCH 2/2] fix: use suffix instead of full match --- .../usecases/github/rest/getInstalledRepositories.ts | 2 +- backend/src/services/githubIntegrationService.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts b/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts index d516bc940c..949d96e406 100644 --- a/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts +++ b/backend/src/serverless/integrations/usecases/github/rest/getInstalledRepositories.ts @@ -16,7 +16,7 @@ const normalizeForkedFrom = (forkedFrom: string | null): string | 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 === 'https://github.com/torvalds/linux') { + if (forkedFrom.endsWith('github.com/torvalds/linux')) { return 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux' } diff --git a/backend/src/services/githubIntegrationService.ts b/backend/src/services/githubIntegrationService.ts index 8e7c99b2ae..caaf076a76 100644 --- a/backend/src/services/githubIntegrationService.ts +++ b/backend/src/services/githubIntegrationService.ts @@ -26,7 +26,7 @@ export default class GithubIntegrationService { // 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 === 'https://github.com/torvalds/linux') { + if (forkedFrom.endsWith('github.com/torvalds/linux')) { return 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux' }