Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> => {
const REPOS_PER_PAGE = 100

Expand Down Expand Up @@ -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),
})
}

Expand Down
21 changes: 19 additions & 2 deletions backend/src/services/githubIntegrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down