-
Notifications
You must be signed in to change notification settings - Fork 31
86 lines (77 loc) · 3.7 KB
/
review-check.yml
File metadata and controls
86 lines (77 loc) · 3.7 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Review Validation
on:
pull_request_review:
types: [submitted, dismissed]
pull_request:
types: [opened, synchronize, reopened]
merge_group:
permissions:
contents: read
pull-requests: read
statuses: write
jobs:
review_validation:
runs-on: ubuntu-latest
steps:
- name: Merge queue pass-through
if: ${{ github.event_name == 'merge_group' }}
run: echo "Review already validated before entering merge queue"
- name: Checkout base branch
if: ${{ github.event_name != 'merge_group' }}
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.ref }}
sparse-checkout: |
.github/REQUIRED_TEAMS
.github/scripts
sparse-checkout-cone-mode: false
- name: Validate approved review from authorized reviewer
if: ${{ github.event_name != 'merge_group' }}
uses: actions/github-script@v8
env:
ORG_TOKEN: ${{ secrets.DAX_PAT }}
with:
script: |
const { loadRequiredTeams, findAuthorizedApproval } = await import(`${process.cwd()}/.github/scripts/review-helpers.mjs`);
const teams = loadRequiredTeams();
const sha = context.payload.pull_request.head.sha;
const repo = { owner: context.repo.owner, repo: context.repo.repo };
const teamsList = teams.map(t => `@duckduckgo/${t}`).join(', ');
async function setReviewStatus({ state, description }) {
await github.rest.repos.createCommitStatus({
...repo,
sha,
state,
context: 'Authorized Review',
description: description.substring(0, 140)
});
}
let approval;
try {
approval = await findAuthorizedApproval(github, {
...repo,
prNumber: context.payload.pull_request.number,
org: 'duckduckgo',
teams,
orgToken: process.env.ORG_TOKEN || undefined
});
} catch (error) {
const msg = error.status === 401
? 'DAX_PAT returned 401 — token may be expired or misconfigured'
: `Review validation failed: ${error.message} (status: ${error.status ?? 'unknown'})`;
await setReviewStatus({ state: 'error', description: msg });
core.setFailed(msg);
return;
}
if (approval) {
const via = approval.team ? `(member of ${approval.team})` : '';
const desc = `Approved by ${approval.user} ${via}`.trim();
await setReviewStatus({ state: 'success', description: desc });
core.info(`✅ ${desc}`);
} else {
await setReviewStatus({
state: 'pending',
description: `Waiting for approval. Required teams: ${teamsList}`
});
core.info('⏳ No approval yet — commit status set to pending');
}