diff --git a/src/config.ts b/src/config.ts index f884c86..f7e74fd 100644 --- a/src/config.ts +++ b/src/config.ts @@ -4,6 +4,7 @@ import fs from 'fs' interface Group { name: string + matchLabel?: string reviewers?: number internal_reviewers?: number usernames: string[] diff --git a/src/lottery.ts b/src/lottery.ts index 18898de..5a75542 100644 --- a/src/lottery.ts +++ b/src/lottery.ts @@ -6,6 +6,7 @@ export interface Pull { user: {login: string} | null number: number draft?: boolean + labels: {name: string}[] | null } interface Env { repository: string @@ -79,17 +80,22 @@ class Lottery { for (const { reviewers, internal_reviewers: internalReviewers, - usernames + usernames, + matchLabel } of this.config.groups) { - const reviewersToRequest = - usernames.includes(author) && internalReviewers - ? internalReviewers - : reviewers - - if (reviewersToRequest) { - selected = selected.concat( - this.pickRandom(usernames, reviewersToRequest, selected.concat(author)) - ) + const labels = this.getPRLabels() + const shouldRunForGroup = matchLabel === undefined || labels.length === 0 || labels.includes(matchLabel) + if (shouldRunForGroup) { + const reviewersToRequest = + usernames.includes(author) && internalReviewers + ? internalReviewers + : reviewers + + if (reviewersToRequest) { + selected = selected.concat( + this.pickRandom(usernames, reviewersToRequest, selected.concat(author)) + ) + } } } } catch (error: any) { @@ -138,6 +144,16 @@ class Lottery { return Number(this.pr?.number) } + getPRLabels(): string[] { + const labels = this.pr?.labels?.map((label) => label.name) + + if (labels) { + return labels + } else { + return [] + } + } + async getPR(): Promise { if (this.pr) return this.pr