When running on a schedule, make a better guess about whether we're analyzing the default branch.

This commit is contained in:
Chris Gavin 2022-08-25 10:57:08 +01:00
parent 92c650bfbd
commit 5960bffd3f
No known key found for this signature in database
GPG key ID: 07F950B80C27E4DA
6 changed files with 59 additions and 10 deletions

View file

@ -860,17 +860,23 @@ function getWorkflowEvent(): any {
}
}
function removeRefsHeadsPrefix(ref: string): string {
return ref.startsWith("refs/heads/") ? ref.slice("refs/heads/".length) : ref;
}
// Is the version of the repository we are currently analyzing from the default branch,
// or alternatively from another branch or a pull request.
export async function isAnalyzingDefaultBranch(): Promise<boolean> {
// Get the current ref and trim and refs/heads/ prefix
let currentRef = await getRef();
currentRef = currentRef.startsWith("refs/heads/")
? currentRef.slice("refs/heads/".length)
: currentRef;
currentRef = removeRefsHeadsPrefix(currentRef);
const event = getWorkflowEvent();
const defaultBranch = event?.repository?.default_branch;
let defaultBranch = event?.repository?.default_branch;
if (process.env.GITHUB_EVENT_NAME === "schedule") {
defaultBranch = removeRefsHeadsPrefix(getRequiredEnvParam("GITHUB_REF"));
}
return currentRef === defaultBranch;
}