From 4b42944ca031682d61a41d2f199432afec3883fb Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 18 Jan 2022 22:46:08 +0100 Subject: [PATCH] chore: small fix not to remove the label if the author was the last event to the issues Signed-off-by: blam --- scripts/goalie-labels.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/scripts/goalie-labels.js b/scripts/goalie-labels.js index adedc35d42..e2684dfd81 100644 --- a/scripts/goalie-labels.js +++ b/scripts/goalie-labels.js @@ -88,17 +88,40 @@ module.exports = async ({ github, context, core }) => { } } + // if all required reviewers have reviewed if (hasReviewed.size === expectedReviewers.size) { - await github.rest.issues - .removeLabel({ + const recentEventsForPR = await github.paginate( + github.issues.listEvents, + { issue_number: pullRequest.number, owner: context.repo.owner, repo: context.repo.repo, - name: 'awaiting-review', - }) - .catch(e => { - console.error(e); - }); + }, + ); + + const { data: pr } = await github.pulls.get({ + issue_number: pullRequest.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + // if the last event for the issue is not by the author, remove the label + if ( + recentEventsForPR[recentEventsForPR.length - 1].actor.login !== + pr.author.login + ) { + await github.rest.issues + .removeLabel({ + issue_number: pullRequest.number, + owner: context.repo.owner, + repo: context.repo.repo, + name: 'awaiting-review', + }) + .catch(e => { + console.error(e); + }); + } + // add the awaiting-review label to tell us that the PR is waiting on reviews } else { await github.rest.issues .addLabels({