From 59ffee7a2c5f08abec86d9a7cc9d31a0acd8b7ec Mon Sep 17 00:00:00 2001 From: Muunatic Date: Fri, 6 Sep 2024 21:50:03 +0700 Subject: [PATCH 1/2] feat(prs): tag maintainers for non user prs --- src/class/prsReview.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/class/prsReview.ts b/src/class/prsReview.ts index f8a7f29..b420c14 100644 --- a/src/class/prsReview.ts +++ b/src/class/prsReview.ts @@ -127,6 +127,19 @@ export default class PullRequestReview { * @returns {Promise} */ public async botPRs(): Promise { + const maintainers:string[] = []; + await this.context.octokit.pulls.listReviews({ + owner: this.context.payload.repository.owner.login, + repo: this.context.payload.repository.name, + pull_number: this.context.payload.pull_request.number + }).then((a) => { + a.data.forEach((data) => { + if (data.user?.login && !maintainers.includes(`@${data.user.login}`) && this.context.payload.review.user.login !== data.user.login && data.user.type.toLowerCase() !== "bot" && (data.author_association === "COLLABORATOR" || data.author_association === "MEMBER" || data.author_association === "OWNER")) { + maintainers.push(`@${data.user.login}`); + } + }); + }); + if (this.context.payload.sender.login === this.context.payload.repository.owner.login) { // Owner if (this.context.payload.review.state === "approved") { @@ -137,7 +150,7 @@ export default class PullRequestReview { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } } else if (this.context.payload.review.state === "changes_requested") { - const reviewMessage = `@${this.context.payload.pull_request.user.login} your pull request has requested changes by \`[OWNER]\`@${this.context.payload.review.user.login}. Please address their comments before I'm merging this PR, thanks!`; + const reviewMessage = `@${this.context.payload.pull_request.user.login} pull request has requested changes by \`[OWNER]\`@${this.context.payload.review.user.login}. ${maintainers.join(", ")} please address their comments before I'm merging this PR, thanks!`; if (this.context.payload.pull_request.labels.find((a) => a.name === "Approved")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Approved", "Pending"]); } else { @@ -153,7 +166,7 @@ export default class PullRequestReview { await this.createReview(reviewMessage, ["Approved"], ["Pending"]); } } else if (this.context.payload.review.state === "changes_requested") { - const reviewMessage = `Pull request has requested changes by \`[MAINTAINER]\`@${this.context.payload.review.user.login}. PING! @${this.context.payload.pull_request.user.login} Please address their comments before I"m merging this PR, thanks!`; + const reviewMessage = `Pull request has requested changes by \`[MAINTAINER]\`@${this.context.payload.review.user.login}. ${maintainers.join(", ")} please address their comments before I'm merging this PR, thanks!`; if (this.context.payload.pull_request.labels.find((a) => a.name === "Approved")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Approved", "Pending"]); } else { @@ -170,7 +183,7 @@ export default class PullRequestReview { await this.createReview(reviewMessage, ["Others Approved"], ["Pending"]); } } else if (this.context.payload.review.state === "changes_requested") { - const reviewMessage = `Pull request has requested changes by @${this.context.payload.review.user.login}. PING! @${this.context.payload.pull_request.user.login} Please address their comments before I'm merging this PR, thanks!`; + const reviewMessage = `Pull request has requested changes by @${this.context.payload.review.user.login}. ${maintainers.join(", ")} please address their comments before I'm merging this PR, thanks!`; if (this.context.payload.pull_request.labels.find((a) => a.name === "Others Approved")) { await this.createReview(reviewMessage, ["Requested Changes"], ["Others Approved", "Pending"]); } else { From 95b98e8e11edcf2d9d1a7591c4b204d5abd018d1 Mon Sep 17 00:00:00 2001 From: wakame Date: Thu, 12 Sep 2024 19:30:01 +0700 Subject: [PATCH 2/2] refactor: use map method Co-authored-by: Haruyaki <52639021+HarunamiYaki@users.noreply.github.com> --- src/class/prsReview.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/class/prsReview.ts b/src/class/prsReview.ts index b420c14..3b31b2a 100644 --- a/src/class/prsReview.ts +++ b/src/class/prsReview.ts @@ -127,19 +127,20 @@ export default class PullRequestReview { * @returns {Promise} */ public async botPRs(): Promise { - const maintainers:string[] = []; - await this.context.octokit.pulls.listReviews({ + const maintainers: ReadonlyArray = await this.context.octokit.pulls.listReviews({ owner: this.context.payload.repository.owner.login, repo: this.context.payload.repository.name, pull_number: this.context.payload.pull_request.number - }).then((a) => { - a.data.forEach((data) => { - if (data.user?.login && !maintainers.includes(`@${data.user.login}`) && this.context.payload.review.user.login !== data.user.login && data.user.type.toLowerCase() !== "bot" && (data.author_association === "COLLABORATOR" || data.author_association === "MEMBER" || data.author_association === "OWNER")) { - maintainers.push(`@${data.user.login}`); - } + }).then((response) => { + return response.data.filter((data) => + data.user?.login && + this.context.payload.review.user.login !== data.user.login && + data.user.type.toLowerCase() !== "bot" && + ["COLLABORATOR", "MEMBER", "OWNER"].includes(data.author_association) + ).map((data) => { + return `@${data.user?.login}`; }); }); - if (this.context.payload.sender.login === this.context.payload.repository.owner.login) { // Owner if (this.context.payload.review.state === "approved") {