From c674fc0225664858abb6cc91591d357813cbcd74 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 24 Jul 2021 04:39:23 -0700 Subject: [PATCH] Add a dedicated "Manage PRs" workflow job for review request The workflow result might indicate either that the PR author could require assistance from a maintainer or that something is wrong with the system. In this case, the situation is brought to the attention of the maintainers by requesting a pull request review from them. Due to the need to avoid requesting review from a maintainer when they are the PR author (which is not allowed and thus would result in a spurious workflow failure), the code for requesting this review is not as trivial as might be expected. Previously, this code was duplicated at multiple places in the workflow, and would become more so as additional code is added. The workflow is made cleaner by moving that duplicated code to a single dedicated job, which is facilitated by the recent reworking of the workflow structure. This is a pure refactoring and should have no effect on the workflow behavior. --- .github/workflows/manage-prs.yml | 63 +++++++++++++------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/.github/workflows/manage-prs.yml b/.github/workflows/manage-prs.yml index 2f6dcaeb..02d2ad6d 100644 --- a/.github/workflows/manage-prs.yml +++ b/.github/workflows/manage-prs.yml @@ -470,37 +470,12 @@ jobs: Once that is done, it will be merged automatically. - - name: Request a review in case assistance is required - if: contains(toJSON(env.MAINTAINERS), github.actor) != true # Don't attempt to request review from PR author. - uses: octokit/request-action@v2.x - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - route: POST /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers - owner: ${{ github.repository_owner }} - repo: ${{ github.event.repository.name }} - pull_number: ${{ github.event.pull_request.number }}${{ github.event.issue.number }} - reviewers: ${{ env.MAINTAINERS }} - not-submission: needs: - parse if: needs.parse.outputs.type != 'submission' # These request types can't be automatically approved. runs-on: ubuntu-latest - steps: - - name: Request pull request review - if: contains(toJSON(env.MAINTAINERS), github.actor) != true - uses: octokit/request-action@v2.x - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - route: POST /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers - owner: ${{ github.repository_owner }} - repo: ${{ github.event.repository.name }} - pull_number: ${{ github.event.pull_request.number }}${{ github.event.issue.number }} - reviewers: ${{ env.MAINTAINERS }} - - name: Comment on required review uses: octokit/request-action@v2.x env: @@ -543,18 +518,6 @@ jobs: labels: | - "status: maintenance required" - - name: Request pull request review - if: contains(toJSON(env.MAINTAINERS), github.actor) != true - uses: octokit/request-action@v2.x - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - route: POST /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers - owner: ${{ github.repository_owner }} - repo: ${{ github.event.repository.name }} - pull_number: ${{ github.event.pull_request.number }}${{ github.event.issue.number }} - reviewers: ${{ env.MAINTAINERS }} - - name: Comment on unexpected failure uses: octokit/request-action@v2.x env: @@ -582,3 +545,29 @@ jobs: :warning::warning::warning::warning: SLACK_COLOR: danger MSG_MINIMAL: true + + request-review: + needs: + - merge-fail + - not-submission + - unexpected-fail + if: > + always() && + ( + needs.merge-fail.result != 'skipped' || + needs.not-submission.result != 'skipped' || + needs.unexpected-fail.result != 'skipped' + ) + runs-on: ubuntu-latest + steps: + - name: Request pull request review from maintainer + if: contains(toJSON(env.MAINTAINERS), github.actor) != true # Don't attempt to request review from PR author. + uses: octokit/request-action@v2.x + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + route: POST /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers + owner: ${{ github.repository_owner }} + repo: ${{ github.event.repository.name }} + pull_number: ${{ github.event.pull_request.number }}${{ github.event.issue.number }} + reviewers: ${{ env.MAINTAINERS }}