Skip to content

Commit

Permalink
feat: add authors matchconfig option
Browse files Browse the repository at this point in the history
  • Loading branch information
fm1randa committed May 10, 2023
1 parent 2d89bd5 commit d4e405a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Minimatch} from 'minimatch';
interface MatchConfig {
all?: string[];
any?: string[];
authors?: string[];
}

type StringOrMatchConfig = string | MatchConfig;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand All @@ -226,6 +252,12 @@ function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean {
}
}

if (matchConfig.authors !== undefined) {
if (!checkAuthors(matchConfig.authors)) {
return false;
}
}

return true;
}

Expand Down

0 comments on commit d4e405a

Please sign in to comment.