mirror of
https://github.com/actions/labeler.git
synced 2025-12-14 13:47:02 +00:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import * as core from '@actions/core';
|
|
import * as github from '@actions/github';
|
|
|
|
function getHeadBranchName(): string | undefined {
|
|
const pullRequest = github.context.payload.pull_request;
|
|
if (!pullRequest) {
|
|
return undefined;
|
|
}
|
|
|
|
return pullRequest.head?.ref;
|
|
}
|
|
|
|
export function checkBranch(glob: string[]): boolean {
|
|
const branchName = getHeadBranchName();
|
|
if (!branchName) {
|
|
core.debug(` no branch name`);
|
|
return false;
|
|
}
|
|
|
|
core.debug(` checking "branch" pattern against ${branchName}`);
|
|
const matchers = glob.map(g => new RegExp(g));
|
|
for (const matcher of matchers) {
|
|
if (matchBranchPattern(matcher, branchName)) {
|
|
core.debug(` "branch" patterns matched against ${branchName}`);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
core.debug(` "branch" patterns did not match against ${branchName}`);
|
|
return false;
|
|
}
|
|
|
|
function matchBranchPattern(matcher: RegExp, branchName: string): boolean {
|
|
core.debug(` - ${matcher}`);
|
|
if (matcher.test(branchName)) {
|
|
core.debug(` "branch" pattern matched`);
|
|
return true;
|
|
}
|
|
|
|
core.debug(` ${matcher} did not match`);
|
|
return false;
|
|
}
|