Debian Codegraph @

.github/workflows/review.yml

raw
1 name: Pull request reviews
2
3 on:
4 pull_request_review:
5 types: [submitted]
6
7 jobs:
8 check-author:
9 if: github.event.review.state == 'approved'
10 runs-on: ubuntu-latest
11 permissions:
12 pull-requests: write
13 contents: read
14 issues: write
15 steps:
16 - name: Check if PR author is a contributor
17 uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
18 with:
19 script: |
20 const { pull_request, review } = context.payload;
21 const { owner, repo } = context.repo;
22
23 const author = pull_request.user.login;
24 const reviewer = review.user.login;
25
26 const blacklistedAuthors = [
27 "dependabot[bot]",
28 ];
29
30 if (blacklistedAuthors.includes(author)) {
31 core.info("Author is blacklisted from nudge, skipping.");
32 return;
33 }
34
35 if (reviewer === author) {
36 core.info("Author reviewed their own pull request, skipping.");
37 return;
38 }
39
40 const getPermissionLevel = async (username) => {
41 const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
42 username,
43 owner,
44 repo,
45 });
46
47 return data.permission;
48 };
49
50 const isMaintainer = async (username) =>
51 ["maintain", "admin"].includes(await getPermissionLevel(username));
52
53 const isContributor = async (username) =>
54 ["write", "maintain", "admin"].includes(await getPermissionLevel(username));
55
56 if (await isContributor(author)) {
57 core.info(`Author @${author} already has write access.`);
58 return;
59 }
60
61 if (!await isMaintainer(reviewer)) {
62 core.info(`Reviewer @${reviewer} is not a maintainer.`);
63 return;
64 }
65
66 const comments = await github.paginate(github.rest.issues.listComments, {
67 issue_number: pull_request.number,
68 per_page: 100,
69 owner,
70 repo,
71 });
72
73 const nudgeMarker = "<!-- @jj-vcs/contributors nudge -->";
74
75 if (comments.some(c => (c.body || "").includes(nudgeMarker))) {
76 core.info("Reviewer has already been nudged.");
77 return;
78 };
79
80 const body = `Hey @martinvonz! Please `
81 + `make sure to add ${author} to jj-vcs/contributors so they `
82 + "can merge their pull request. Feel free to also drop a note "
83 + "in Discord so they can get their contributor role. Thanks!";
84
85 await github.rest.issues.createComment({
86 issue_number: pull_request.number,
87 body: nudgeMarker + body,
88 owner,
89 repo,
90 });
91
92 core.notice(`Pinged martinvonz to add ${author} to jj-vcs/contributors.`);