From 673e73ea422b08098e929008ef0c3a53732165c3 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 20 Jan 2022 08:30:54 +0100 Subject: [PATCH] chore: events endpoint does not return all events.. so we go get them ourselves Signed-off-by: blam --- .github/workflows/goalie.yaml | 8 ++-- scripts/goalie-labels.js | 71 +++++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/.github/workflows/goalie.yaml b/.github/workflows/goalie.yaml index 93ca4209fc..4c581e5b19 100644 --- a/.github/workflows/goalie.yaml +++ b/.github/workflows/goalie.yaml @@ -1,8 +1,10 @@ # on a review from someone in the reviewers group, remove the awaiting-review label and add the awaiting-author label name: 'goalie: run cron' -on: - schedule: - - cron: '* * * * *' +# on: +# schedule: +# - cron: '* * * * *' + +on: push jobs: label: diff --git a/scripts/goalie-labels.js b/scripts/goalie-labels.js index 99f3f92ff4..abcb3eb69c 100644 --- a/scripts/goalie-labels.js +++ b/scripts/goalie-labels.js @@ -16,6 +16,60 @@ const Codeowners = require('codeowners'); +const getRepoEvents = ({ github, context, pull_number }) => { + const commits = await github.paginate(github.rest.pulls.listCommits, { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number, + }); + + const reviews = await github.paginate(github.rest.pulls.listReviews, { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number, + }); + + const pullComments = await github.paginate( + 'GET /repos/{owner}/{repo}/pulls/{pull_number}/comments', + { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number, + }, + ); + + const comments = await github.paginate(github.rest.issues.listComments, { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pull_number, + }); + + const events = [ + ...reviews.map(({ user, submitted_at }) => ({ + user, + updated_at: submitted_at, + type: 'review', + })), + ...commits.map(({ commit, author }) => ({ + user: author, + updated_at: commit.author.date, + type: 'commit', + })), + ...pullComments.map(({ user, updated_at }) => ({ + user, + updated_at, + type: 'pr_comment', + })), + ...comments.map(({ user, updated_at }) => ({ + user, + updated_at, + type: 'pr_comment', + })), + ]; + + return events.sort((a, b) => new Date(a.updated_at) - new Date(b.updated_at)); +}; + module.exports = async ({ github, context, core }) => { // first get all open pull requests const allPullRequests = await github.paginate(github.rest.pulls.list, { @@ -91,19 +145,14 @@ module.exports = async ({ github, context, core }) => { // if all required reviewers have reviewed if (hasReviewed.size === expectedReviewers.size) { - const recentEventsForPR = await github.paginate( - github.rest.issues.listEvents, - { - issue_number: pullRequest.number, - owner: context.repo.owner, - repo: context.repo.repo, - }, - ); - + const repoEvents = await getRepoEvents({ + github, + context, + pull_number: pullRequest.number, + }); // if the last event for the issue is not by the author, remove the label if ( - recentEventsForPR[recentEventsForPR.length - 1].actor.login !== - pullRequest.user.login + repoEvents[repoEvents.length - 1].user.login !== pullRequest.user.login ) { await github.rest.issues .removeLabel({