Skip to content

data(controls): sharper OpenCRE links for AT-06 and AT-11 #106

data(controls): sharper OpenCRE links for AT-06 and AT-11

data(controls): sharper OpenCRE links for AT-06 and AT-11 #106

name: Require maintainer approval

Check warning on line 1 in .github/workflows/require-maintainer-approval.yml

View workflow run for this annotation

GitHub Actions / Require maintainer approval

Workflow execution policy warning (evaluate mode)

On November 2, 2026, GitHub will restrict `pull_request_target` on public repositories by default. To continue allowing the event trigger, configure an Actions policy. Learn more: https://gh.io/securely-using-pull_request_target#default-policy-for-pull_request_target
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.');
}