Commit f95a41c08c

f95a41c08c78df153530dedd01cf682dafbff590

parent: 259314537a

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-02-27 23:33 UTC

Add workflow to notify maintainer (me) when pr needs reivew

Layout: unified · split

.github/workflows/pr-comment.yml +87
@@ -4,9 +4,12 @@ on:
44 workflow_run:
55 workflows: ["PR Check"]
66 types: [completed]
7 pull_request_review:
8 types: [submitted]
79
810permissions:
911 actions: read
12 checks: read
1013 contents: read
1114 pull-requests: write
1215
@@ -132,3 +135,87 @@ jobs:
132135 });
133136 console.log('Updated bot comment.');
134137 }
138
139 review-notify:
140 name: Notify maintainer
141 runs-on: ubuntu-latest
142 if: github.event_name == 'pull_request_review'
143
144 steps:
145 - uses: actions/checkout@v4
146
147 - name: Fetch review and CI context
148 id: context
149 uses: actions/github-script@v7
150 with:
151 github-token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
152 script: |
153 const fs = require('fs');
154 const pr = context.payload.pull_request;
155 const { owner, repo } = context.repo;
156
157 // Fetch reviews — extract user login and state
158 const { data: reviews } = await github.rest.pulls.listReviews({
159 owner, repo, pull_number: pr.number, per_page: 100,
160 });
161 const reviewData = reviews.map(r => ({
162 user: r.user.login,
163 state: r.state,
164 }));
165
166 // Fetch check runs for the PR head SHA
167 const { data: { check_runs } } = await github.rest.checks.listForRef({
168 owner, repo, ref: pr.head.sha, per_page: 100,
169 });
170 const checkData = check_runs.map(cr => ({
171 status: cr.status,
172 conclusion: cr.conclusion,
173 }));
174
175 // Check if we already posted the notification
176 const marker = '<!-- pr-review-ready -->';
177 const { data: comments } = await github.rest.issues.listComments({
178 owner, repo, issue_number: pr.number, per_page: 100,
179 });
180 const alreadyNotified = comments.some(c => c.body.includes(marker));
181
182 // Write data for Python
183 fs.mkdirSync('pr-meta', { recursive: true });
184 fs.writeFileSync('pr-meta/reviews.json', JSON.stringify(reviewData));
185 fs.writeFileSync('pr-meta/check-runs.json', JSON.stringify(checkData));
186 fs.writeFileSync('pr-meta/already-notified.txt', String(alreadyNotified));
187
188 core.setOutput('pr_number', pr.number);
189
190 - name: Check review readiness
191 run: python lib/checks/check-review-ready.py
192
193 - name: Post notification
194 uses: actions/github-script@v7
195 with:
196 github-token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
197 script: |
198 const fs = require('fs');
199 const actionFile = 'pr-meta/action.txt';
200 if (!fs.existsSync(actionFile)) return;
201
202 const action = fs.readFileSync(actionFile, 'utf8').trim();
203 if (action !== 'notify') {
204 console.log('Not ready for review — skipping.');
205 return;
206 }
207
208 const body = [
209 '<!-- pr-review-ready -->',
210 'This PR is now ready to be merged, pending maintainer review. All checks are passing and it has been peer-reviewed.',
211 '',
212 '@Lissy93 - Please evaluate, and either merge or leave feedback.',
213 ].join('\n');
214
215 await github.rest.issues.createComment({
216 owner: context.repo.owner,
217 repo: context.repo.repo,
218 issue_number: parseInt('${{ steps.context.outputs.pr_number }}'),
219 body,
220 });
221 console.log('Posted maintainer notification.');
lib/checks/check-review-ready.py added +90
@@ -0,0 +1,90 @@
1"""Decides whether a PR is ready for maintainer review.
2
3Conditions: 2+ approvals from external contributors AND all CI checks passing.
4
5Reads:
6 pr-meta/reviews.json — array of {user, state} from GitHub API
7 pr-meta/check-runs.json — array of {status, conclusion} from GitHub API
8 pr-meta/already-notified.txt — "true" if notification comment already exists
9
10Writes:
11 pr-meta/action.txt — "notify" or "skip"
12"""
13
14import json
15import os
16
17WORK_DIR = "pr-meta"
18MAINTAINER = "Lissy93"
19REQUIRED_APPROVALS = 2
20PASSING_CONCLUSIONS = {"success", "skipped", "neutral"}
21
22
23def read_json(filename):
24 """Load a JSON file from the work directory, or empty list on error."""
25 try:
26 with open(os.path.join(WORK_DIR, filename)) as f:
27 return json.load(f)
28 except Exception:
29 return []
30
31
32def count_external_approvals(reviews):
33 """Count unique non-maintainer users who approved."""
34 approvers = {
35 r["user"]
36 for r in reviews
37 if r.get("state") == "APPROVED"
38 and r.get("user", "").lower() != MAINTAINER.lower()
39 }
40 return len(approvers)
41
42
43def all_checks_passing(check_runs):
44 """Return True if every check run completed successfully."""
45 if not check_runs:
46 return False
47 return all(
48 cr.get("status") == "completed"
49 and cr.get("conclusion") in PASSING_CONCLUSIONS
50 for cr in check_runs
51 )
52
53
54def already_notified():
55 """Return True if the notification comment already exists on the PR."""
56 try:
57 with open(os.path.join(WORK_DIR, "already-notified.txt")) as f:
58 return f.read().strip().lower() == "true"
59 except Exception:
60 return False
61
62
63def write_action(action):
64 os.makedirs(WORK_DIR, exist_ok=True)
65 with open(os.path.join(WORK_DIR, "action.txt"), "w") as f:
66 f.write(action)
67
68
69def main():
70 if already_notified():
71 write_action("skip")
72 return
73
74 reviews = read_json("reviews.json")
75 approvals = count_external_approvals(reviews)
76
77 if approvals < REQUIRED_APPROVALS:
78 write_action("skip")
79 return
80
81 check_runs = read_json("check-runs.json")
82 if not all_checks_passing(check_runs):
83 write_action("skip")
84 return
85
86 write_action("notify")
87
88
89if __name__ == "__main__":
90 main()