Repository navigation
70 lines (62 loc) · 2.52 KB
/
Copy pathcheck_docs_review.yml
File metadata and controls
70 lines (62 loc) · 2.52 KB
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
67
68
69
70
# Docs review hold — workflow 2/3
#
# Fires on every review submission or dismissal. If at least one MEMBER/OWNER
# has an APPROVED review and the hold label is present, writes the PR number to
# an artifact for remove_docs_review_label.yml (3/3) to act on.
#
# The workflow_run indirection exists for a security reason: pull_request_review
# events from fork PRs run with a read-only token, so label writes must happen in
# a separate workflow that runs in the base-repo context with a write token.
#
# Review state check is intentionally simple: any APPROVED review from a
# MEMBER/OWNER is sufficient, regardless of later CHANGES_REQUESTED from the
# same reviewer. Best-effort is good enough here.
name: Check Docs Review
on:
pull_request_review:
types: [submitted, dismissed]
permissions:
contents: read
pull-requests: read
concurrency:
group: pr-labels-check-${{ github.event.pull_request.number }}
cancel-in-progress: false
env:
LABEL_NAME: "docs review on hold"
jobs:
check:
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Check approval and label
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const allowed = ['MEMBER', 'OWNER'];
const reviews = await github.paginate(github.rest.pulls.listReviews, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
per_page: 100,
});
const approved = reviews.some(r => allowed.includes(r.author_association) && r.state === 'APPROVED');
core.info(`Member approval found: ${approved}`);
if (!approved) return;
const labelName = process.env.LABEL_NAME;
const labels = await github.paginate(github.rest.issues.listLabelsOnIssue, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
per_page: 100,
});
if (!labels.some(l => l.name === labelName)) {
core.info(`Label "${labelName}" not found, skipping`);
return;
}
require('fs').writeFileSync('pr-number', String(context.payload.pull_request.number));
- name: Upload PR number
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: docs-review-pr
path: pr-number
if-no-files-found: ignore