diff --git a/src/labeler.ts b/src/labeler.ts index 96e152bc3..0f847d77d 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -6,6 +6,7 @@ import {Minimatch} from 'minimatch'; interface MatchConfig { all?: string[]; any?: string[]; + authors?: string[]; } type StringOrMatchConfig = string | MatchConfig; @@ -71,6 +72,15 @@ function getPrNumber(): number | undefined { return pullRequest.number; } +function getPrAuthor(): string | undefined { + const pullRequest = github.context.payload.pull_request; + if (!pullRequest) { + return undefined; + } + + return pullRequest.user.login; +} + async function getChangedFiles( client: ClientType, prNumber: number @@ -213,6 +223,22 @@ function checkAll(changedFiles: string[], globs: string[]): boolean { return true; } +function checkAuthors(authors: string[]): boolean { + const prAuthor = getPrAuthor(); + if (!prAuthor) { + core.info('Could not get pull request author from context, exiting'); + return false; + } + + if (authors.includes(prAuthor)) { + core.debug(` author ${prAuthor} is on the list`); + return true; + } + + core.debug(` author ${prAuthor} is not on the list`); + return false; +} + function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean { if (matchConfig.all !== undefined) { if (!checkAll(changedFiles, matchConfig.all)) { @@ -226,6 +252,12 @@ function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean { } } + if (matchConfig.authors !== undefined) { + if (!checkAuthors(matchConfig.authors)) { + return false; + } + } + return true; }