From 43e661e6eaa4fc491d476a26416d39b244f7ae4e Mon Sep 17 00:00:00 2001 From: Daniel Wong <97631336+daniel-wong-dfinity-org@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:38:46 +0100 Subject: [PATCH] feat(governance): Automatically remind governance team to update unreleased_changelog.md. (#3342) This happens via a new GitHub Action. What it does is ``` if review is not requested from nns-team { return; } if already reminded { return; } Add a review that reminds the author that they need to update unreleased_changelog.md. ``` Because the reminder is done as a code review, the author is FORCED to acknowledge the reminder. --- .../ci-pr-only-nns-team-reminder.yml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/ci-pr-only-nns-team-reminder.yml diff --git a/.github/workflows/ci-pr-only-nns-team-reminder.yml b/.github/workflows/ci-pr-only-nns-team-reminder.yml new file mode 100644 index 00000000000..9f8577375f5 --- /dev/null +++ b/.github/workflows/ci-pr-only-nns-team-reminder.yml @@ -0,0 +1,68 @@ +name: Governance Unreleased Changelog Reminder + +on: + pull_request: + types: + - review_requested + +jobs: + mainJob: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v6 + id: mainStep + # If the PR requires nns-team to approve, GitHub will force nns-team to + # be in requested_teams. Therefore, the following condition is always + # met when nns-team must approve. (Further filtering takes place in the + # script itself.) + if: contains(github.event.pull_request.requested_teams.*.name, 'nns-team') + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + retries: 3 + script: | + const pullRequestNumber = context.payload.number; + + // Skip reminder if we already reminded (to avoid spam). + const reviews = await github.rest.pulls.listReviews({ + owner: "dfinity", + repo: "ic", + pull_number: pullRequestNumber, + }); + const alreadyRemindedAboutUnreleasedChangelog = reviews + .data + .some(review => review + .body + .startsWith("If this pull request affects the behavior of any canister owned by") + ); + console.log("alreadyRemindedAboutUnreleasedChangelog = " + alreadyRemindedAboutUnreleasedChangelog); + if (alreadyRemindedAboutUnreleasedChangelog) { + return; + } + + // Post a review to remind the author to update unreleased_changelog.md. + // TODO: Figure out how to post in such a way that there is a "Resolve" button nearby. + console.log("Adding reminder to update unreleased_changelog.md..."); + const reminderText = ` + If this pull request affects the behavior of any canister owned by + the Governance team, remember to update the corresponding + unreleased_changes.md file(s). + + To acknowldge this reminder (and unblock the PR), dismiss this + code review by going to the bottom of the pull request page, and + supply one of the following reasons: + + 1. Done. + + 2. No canister behavior changes. + ` + .replace(/^ +/gm, '') + .trim(); + await github.rest.pulls.createReview({ + owner: "dfinity", + repo: "ic", + pull_number: pullRequestNumber, + body: reminderText, + // This is what forces the author to explicitly acknowledge. + event: "REQUEST_CHANGES", + }); + console.log("Reminder was added successfully.");