From 1740edbd3564c9a1e75df6015365b7f5b772f7d4 Mon Sep 17 00:00:00 2001 From: Callahan Kovacs Date: Tue, 11 Jun 2024 17:06:30 -0500 Subject: [PATCH] ci: add reviewers workflow Signed-off-by: Callahan Kovacs --- .github/workflows/add-reviewer-label.yaml | 20 ++++++++++++ .github/workflows/add-reviewers.yaml | 39 +++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .github/workflows/add-reviewer-label.yaml create mode 100644 .github/workflows/add-reviewers.yaml diff --git a/.github/workflows/add-reviewer-label.yaml b/.github/workflows/add-reviewer-label.yaml new file mode 100644 index 00000000000..2f5af1b84fa --- /dev/null +++ b/.github/workflows/add-reviewer-label.yaml @@ -0,0 +1,20 @@ +# Add `needs-starcraft-review` if starcraft-reviewers is added as a reviewer + +name: add-reviewer-label + +on: + pull_request: + types: + - review_requested + +jobs: + add-reviewer-label: + runs-on: ubuntu-latest + steps: + - name: Add 'needs-starcraft-review' label + uses: octokit/request-action@v2 + with: + route: POST /repos/${{ github.repository }}/issues/$ {{ github.event.pull_request.number }}/labels + mediaType: 'application/vnd.github.v3+json' + token: ${{ secrets.GITHUB_TOKEN }} + labels: need-starcraft-review diff --git a/.github/workflows/add-reviewers.yaml b/.github/workflows/add-reviewers.yaml new file mode 100644 index 00000000000..8025e60aadf --- /dev/null +++ b/.github/workflows/add-reviewers.yaml @@ -0,0 +1,39 @@ +# If there are not 2 reviews, re-add starcraft-reviewers when reviewed by the starcraft-reviewers team +# Otherwise, drop the `need-starcraft-review` label + +name: add-reviewer + +on: + pull_request_review: + types: [submitted] + +jobs: + add-reviewer: + runs-on: ubuntu-latest + + steps: + - name: check number of reviews + id: check-reviews + uses: octokit/request-action@v2 + with: + route: GET /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews + mediaType: 'application/vnd.github.v3+json' + token: ${{ secrets.GITHUB_TOKEN }} + + - name: re-add team if there are not enough reviews + if: steps.check-reviews.outputs.data | fromJson | length < 2 + uses: octokit/request-action@v2 + with: + route: POST /repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers + mediaType: 'application/vnd.github.v3+json' + token: ${{ secrets.GITHUB_TOKEN }} + reviewers: starcraft-reviewers + + - name: drop label if there are enough reviews + if: steps.check-reviews.outputs.data | fromJson | length >= 2 + uses: octokit/request-action@v2 + with: + route: DELETE /repos/${{ github.repository }}/issues/$ {{ github.event.pull_request.number }}/labels + mediaType: 'application/vnd.github.v3+json' + token: ${{ secrets.GITHUB_TOKEN }} + labels: need-starcraft-review