@@ -321,6 +321,48 @@ async function fetchGithubOrgLogo(owner: string, bearerToken: string): Promise<s
321321 }
322322}
323323
324+ /**
325+ * Fetches repository information to determine if it's a fork
326+ *
327+ * Makes an API call to GitHub's repos endpoint to retrieve repository details,
328+ * including fork status and parent repository information.
329+ *
330+ * @param owner - GitHub organization or user name
331+ * @param repo - Repository name
332+ * @param bearerToken - Authentication token for GitHub API calls
333+ * @returns Promise resolving to the parent repository URL if forked, null otherwise
334+ */
335+ async function fetchGithubRepoForkInfo (
336+ owner : string ,
337+ repo : string ,
338+ bearerToken : string ,
339+ ) : Promise < string | null > {
340+ try {
341+ const response = await axios . get ( `https://api.github.com/repos/${ owner } /${ repo } ` , {
342+ headers : {
343+ Authorization : `Bearer ${ bearerToken } ` ,
344+ 'Content-Type' : 'application/json' ,
345+ Accept : 'application/json' ,
346+ } ,
347+ timeout : 10000 ,
348+ } )
349+
350+ if ( response . data . fork && response . data . parent ) {
351+ let forkedFrom = response . data . parent . html_url
352+ if ( forkedFrom . endsWith ( 'github.com/torvalds/linux' ) ) {
353+ // use git url instead of github as it's the one onboarded in our system
354+ forkedFrom = 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux'
355+ }
356+ return forkedFrom
357+ }
358+
359+ return null
360+ } catch ( error ) {
361+ log . warn ( `Failed to fetch fork info for ${ owner } /${ repo } : ${ error . message } ` )
362+ return null
363+ }
364+ }
365+
324366/**
325367 * Creates a GitHub integration for the specified project
326368 *
@@ -343,8 +385,9 @@ async function createGithubIntegration(
343385 // Parse GitHub repo URL to extract owner and repo name
344386 const { owner, repo } = parseGithubUrl ( project . repoUrl )
345387
346- // Fetch organization logo
388+ // Fetch organization logo and fork information
347389 const orgLogo = await fetchGithubOrgLogo ( owner , githubToken )
390+ const forkedFrom = await fetchGithubRepoForkInfo ( owner , repo , githubToken )
348391
349392 // Create integration
350393 const integrationUrl = `${ process . env [ 'CROWD_API_SERVICE_URL' ] } /github-nango-connect`
@@ -362,6 +405,7 @@ async function createGithubIntegration(
362405 {
363406 name : repo ,
364407 url : project . repoUrl ,
408+ forkedFrom,
365409 updatedAt : new Date ( ) . toISOString ( ) ,
366410 } ,
367411 ] ,
0 commit comments