Skip to content
Merged
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
46 changes: 45 additions & 1 deletion services/apps/script_executor_worker/src/bin/onboard-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,48 @@ async function fetchGithubOrgLogo(owner: string, bearerToken: string): Promise<s
}
}

/**
* Fetches repository information to determine if it's a fork
*
* Makes an API call to GitHub's repos endpoint to retrieve repository details,
* including fork status and parent repository information.
*
* @param owner - GitHub organization or user name
* @param repo - Repository name
* @param bearerToken - Authentication token for GitHub API calls
* @returns Promise resolving to the parent repository URL if forked, null otherwise
*/
async function fetchGithubRepoForkInfo(
owner: string,
repo: string,
bearerToken: string,
): Promise<string | null> {
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
*
Expand All @@ -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`
Expand All @@ -362,6 +405,7 @@ async function createGithubIntegration(
{
name: repo,
url: project.repoUrl,
forkedFrom,
updatedAt: new Date().toISOString(),
},
],
Expand Down
Loading