Repository navigation
data(controls): sharper OpenCRE links for AT-06 and AT-11 #106
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Require maintainer approval | ||
|
Check warning on line 1 in .github/workflows/require-maintainer-approval.yml
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened, synchronize, reopened] | ||
| branches: [main] | ||
| pull_request_review: | ||
| types: [submitted, dismissed] | ||
| permissions: | ||
| contents: read | ||
| jobs: | ||
| gate: | ||
| runs-on: ubuntu-latest | ||
| # Reads the PR and its reviews, then fails the job if no maintainer | ||
| # approved the head commit. It writes nothing, so no write scope. | ||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| if: github.event.pull_request.base.ref == 'main' | ||
| steps: | ||
| - name: Check for maintainer approval | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | ||
| with: | ||
| script: | | ||
| const MAINTAINERS = ['imran-siddique', 'pforest', 'podcastinator', 'Qiang-Xu']; | ||
| const author = context.payload.pull_request.user.login; | ||
| if (MAINTAINERS.includes(author)) { | ||
| core.info('Author ' + author + ' is a maintainer, skipping gate'); | ||
| return; | ||
| } | ||
| const prNumber = context.payload.pull_request.number; | ||
| const { data: pr } = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: prNumber, | ||
| }); | ||
| const headSha = pr.head.sha; | ||
| const reviews = await github.paginate(github.rest.pulls.listReviews, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: prNumber, | ||
| }); | ||
| const latestByMaintainer = new Map(); | ||
| for (const review of reviews) { | ||
| if ( | ||
| review.user && | ||
| review.user.type === 'User' && | ||
| MAINTAINERS.includes(review.user.login) && | ||
| review.state !== 'COMMENTED' | ||
| ) { | ||
| latestByMaintainer.set(review.user.login, review); | ||
| } | ||
| } | ||
| const approved = [...latestByMaintainer.values()].some( | ||
| (r) => r.state === 'APPROVED' && r.commit_id === headSha | ||
| ); | ||
| if (!approved) { | ||
| core.setFailed('Waiting for maintainer approval of the current head commit before merging.'); | ||
| } | ||