Skip to content

fix(sbom-tools): allow CodeQL report fetching for PR heads #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2024
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
13 changes: 10 additions & 3 deletions packages/sbom-tools/src/commands/fetch-codeql-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ResolvedCommitInformation = {
repo: string;
forPackage?: string;
commit: string;
alternativeRef?: string;
};

type UnresolvedRepoInformation = Omit<ResolvedCommitInformation, 'commit'> &
Expand All @@ -25,7 +26,7 @@ type UnresolvedRepoInformation = Omit<ResolvedCommitInformation, 'commit'> &
// Get CodeQL SARIF reports for a single commit in a single repository
async function getSingleCommitSarif(
octokit: Octokit,
{ owner, repo, commit }: ResolvedCommitInformation
{ owner, repo, commit, alternativeRef }: ResolvedCommitInformation
): Promise<unknown[]> {
const reportIds = new Set<number>();
for (let page = 0; ; page++) {
Expand All @@ -36,7 +37,7 @@ async function getSingleCommitSarif(
});
const previousPageAlreadyHadSomeData = reportIds.size > 0;
for (const item of data) {
if (item.commit_sha === commit) {
if (item.commit_sha === commit || item.ref === alternativeRef) {
reportIds.add(item.id);
}
}
Expand Down Expand Up @@ -183,11 +184,17 @@ async function getCurrentRepo(): Promise<ResolvedCommitInformation> {
encoding: 'utf8',
})
).stdout.trim();

let alternativeRef;
if (process.env.GITHUB_PR_NUMBER) {
alternativeRef = `refs/pull/${process.env.GITHUB_PR_NUMBER}/merge`;
}

const repo = repoForPackageJSON(
JSON.parse(await fs.readFile('package.json', 'utf8')),
'<root>'
);
return { ...repo, commit };
return { ...repo, commit, alternativeRef };
}

export async function fetchCodeQLResults(
Expand Down
Loading