diff --git a/services/apps/script_executor_worker/src/bin/onboard-projects.ts b/services/apps/script_executor_worker/src/bin/onboard-projects.ts index 1143a33b4a..67aaf01d7a 100644 --- a/services/apps/script_executor_worker/src/bin/onboard-projects.ts +++ b/services/apps/script_executor_worker/src/bin/onboard-projects.ts @@ -321,6 +321,48 @@ async function fetchGithubOrgLogo(owner: string, bearerToken: string): Promise { + try { + const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}`, { + headers: { + Authorization: `Bearer ${bearerToken}`, + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + timeout: 10000, + }) + + if (response.data.fork && response.data.parent) { + let forkedFrom = response.data.parent.html_url + if (forkedFrom.endsWith('github.com/torvalds/linux')) { + // use git url instead of github as it's the one onboarded in our system + forkedFrom = 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux' + } + return forkedFrom + } + + return null + } catch (error) { + log.warn(`Failed to fetch fork info for ${owner}/${repo}: ${error.message}`) + return null + } +} + /** * Creates a GitHub integration for the specified project * @@ -343,8 +385,9 @@ async function createGithubIntegration( // Parse GitHub repo URL to extract owner and repo name const { owner, repo } = parseGithubUrl(project.repoUrl) - // Fetch organization logo + // Fetch organization logo and fork information const orgLogo = await fetchGithubOrgLogo(owner, githubToken) + const forkedFrom = await fetchGithubRepoForkInfo(owner, repo, githubToken) // Create integration const integrationUrl = `${process.env['CROWD_API_SERVICE_URL']}/github-nango-connect` @@ -362,6 +405,7 @@ async function createGithubIntegration( { name: repo, url: project.repoUrl, + forkedFrom, updatedAt: new Date().toISOString(), }, ],