summaryrefslogtreecommitdiff
path: root/.github/workflows/dismissed-review.yml
blob: 1d99c1c9cf0633eb1c3265d03671f62672254895 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Dismissed review

on:
  workflow_run:
    workflows:
      - Review dismissed
    types: [completed]

concurrency:
  group: dismissed-review-${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }}
  cancel-in-progress: true

permissions:
  pull-requests: write

defaults:
  run:
    shell: bash

jobs:
  # The `check-cherry-picks` workflow creates review comments which reviewers
  # are encouraged to manually dismiss if they're not relevant.
  # When a CI-generated review is dismissed, this job automatically minimizes
  # it, preventing it from cluttering the PR.
  minimize:
    name: Minimize as resolved
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 2
    steps:
      - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
        with:
          script: |
            // PRs from forks don't have any PRs associated by default.
            // Thus, we request the PR number with an API call *to* the fork's repo.
            // Multiple pull requests can be open from the same head commit, either via
            // different base branches or head branches.
            const { head_repository, head_sha, repository } = context.payload.workflow_run
            await Promise.all(
              (await github.paginate(github.rest.repos.listPullRequestsAssociatedWithCommit, {
                owner: head_repository.owner.login,
                repo: head_repository.name,
                commit_sha: head_sha
              }))
              .filter(pull_request => pull_request.base.repo.id == repository.id)
              .map(async (pull_request) =>
                Promise.all(
                  (await github.paginate(github.rest.pulls.listReviews, {
                    owner: context.repo.owner,
                    repo: context.repo.repo,
                    pull_number: pull_request.number
                  })).filter(review =>
                    review.user.login == 'github-actions[bot]' &&
                    review.state == 'DISMISSED'
                  ).map(review => github.graphql(`
                    mutation($node_id:ID!) {
                      minimizeComment(input: {
                        classifier: RESOLVED,
                        subjectId: $node_id
                      })
                      { clientMutationId }
                    }`,
                    { node_id: review.node_id }
                  ))
                )
              )
            )