Update src/labeler.ts

Safer access of pull_request data.

Co-authored-by: Josh Dales <30500472+joshdales@users.noreply.github.com>
This commit is contained in:
Amiel Martin
2021-09-16 12:22:00 -08:00
committed by GitHub
parent 79c0cc7c0b
commit 27a1d89941

View File

@@ -216,10 +216,10 @@ function checkAll(changedFiles: string[], globs: string[]): boolean {
function checkBranch(glob: string): boolean {
const matcher = new Minimatch(glob);
const branchName = github.context.payload.pull_request!.head.ref;
const branchName = github.context.payload.pull_request?.head.ref;
core.debug(` checking "branch" pattern against ${branchName}`);
core.debug(` - ${printPattern(matcher)}`);
if (!matcher.match(branchName)) {
if (branchName || !matcher.match(branchName)) {
core.debug(` ${printPattern(matcher)} did not match`);
return false;
}