Skip to content

Commit dc0171b

Browse files
committed
add better error messaging
1 parent ede0b6a commit dc0171b

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed
Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
name: Require Jump + Anza approval
22

3-
# ────── trigger on every meaningful PR event ──────
43
on:
54
pull_request:
6-
types: [opened, reopened, synchronize, ready_for_review, converted_to_draft]
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
- ready_for_review
10+
- converted_to_draft
711
pull_request_review:
812
types: [submitted, dismissed, edited]
913

10-
# built-in token is enough (repo-only API)
1114
permissions:
1215
contents: read
1316
pull-requests: read
@@ -20,59 +23,63 @@ jobs:
2023
uses: actions/github-script@v7
2124
with:
2225
script: |
23-
// <-- globals github, context, core are injected by github-script -->
26+
// globals github, context, core are injected by github-script
2427
25-
// ──────── 1. MANUAL ROSTERS – edit as needed ────────
28+
// ──────────── 1. MANUAL ROSTERS ────────────
2629
const jumpApprovers = ['jacobcreech', 'topointon-jump', '0x0ece'];
2730
const anzaApprovers = ['benhawkins18', 'tigarcia', 't-nelson', 'sakridge'];
28-
// ─────────────────────────────────────────────────────
31+
// ───────────────────────────────────────────
2932
3033
const pr = context.payload.pull_request;
31-
if (!pr) {
32-
core.setFailed('No pull_request context'); return;
33-
}
34+
if (!pr) { core.setFailed('No pull_request context'); return; }
3435
35-
// 2. pull every review on this PR
36+
// 2. fetch every review on this PR
3637
const { data: reviews } = await github.rest.pulls.listReviews({
3738
owner: context.repo.owner,
3839
repo: context.repo.repo,
3940
pull_number: pr.number,
4041
per_page: 100
4142
});
4243
43-
// ──────── DEBUG BLOCK #1 – raw reviews ────────
44+
// DEBUG 1: raw events
4445
core.info('=== Raw review events ===');
4546
reviews.forEach(r =>
4647
core.info(`${r.user.login} -> ${r.state} @ ${r.submitted_at}`));
47-
// ───────────────────────────────────────────────
4848
49-
// 3. collapse to effective state per reviewer
50-
const states = {}; // login → {approved, changesRequested}
49+
// 3. reduce to effective state per reviewer
50+
const states = {}; // login → {approved, changesRequested}
5151
for (const r of reviews) {
5252
const u = r.user.login;
5353
states[u] = states[u] || { approved: false, changesRequested: false };
54-
if (r.state === 'APPROVED') states[u].approved = true;
55-
if (r.state === 'REQUEST_CHANGES') states[u].changesRequested = true;
54+
if (r.state === 'APPROVED') states[u].approved = true;
55+
if (r.state === 'REQUEST_CHANGES') states[u].changesRequested = true;
5656
}
5757
58-
// ──────── DEBUG BLOCK #2 – latest state map ────────
58+
// DEBUG 2: effective map
5959
core.info('=== Effective state per reviewer ===');
6060
Object.entries(states).forEach(([u, s]) =>
6161
core.info(`${u}: approved=${s.approved}, changesRequested=${s.changesRequested}`));
62-
// ───────────────────────────────────────────────────
6362
63+
// 4. build final approved-and-not-blocked set
6464
const approved = Object.entries(states)
6565
.filter(([_, s]) => s.approved && !s.changesRequested)
6666
.map(([u]) => u);
6767
68-
// ──────── DEBUG BLOCK #3 – final approved list ────────
68+
// DEBUG 3: final list
6969
core.info(`Approved reviewers counted: ${approved.join(', ') || 'none'}`);
70-
// ───────────────────────────────────────────────────────
7170
71+
// 5. org-level checks
7272
const hasJump = jumpApprovers.some(u => approved.includes(u));
7373
const hasAnza = anzaApprovers.some(u => approved.includes(u));
7474
75-
// 4. nice summary in the PR “Checks” view
75+
// prepare helpful failure message
76+
const missing = [];
77+
if (!hasJump) missing.push(
78+
`Jump approval missing. Any of: ${jumpApprovers.join(', ')}`);
79+
if (!hasAnza) missing.push(
80+
`Anza approval missing. Any of: ${anzaApprovers.join(', ')}`);
81+
82+
// PR-check summary
7683
core.summary
7784
.addHeading('Jump + Anza approval check')
7885
.addTable([
@@ -81,8 +88,8 @@ jobs:
8188
])
8289
.write();
8390
84-
if (!hasJump || !hasAnza) {
85-
core.setFailed('Need at least one Jump and one Anza approval');
91+
if (missing.length) {
92+
core.setFailed(missing.join(' | '));
8693
} else {
8794
core.notice('All required approvals present; merge allowed.');
8895
}

0 commit comments

Comments
 (0)