Skip to content

Commit 592720f

Browse files
add two workflows for PRs
Signed-off-by: Cédrik Fuoco <[email protected]>
1 parent 0bc2117 commit 592720f

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: 'Update Status on Checkbox Change'
2+
3+
on:
4+
# This event is emitted by wadackel/checkbox-workflow-action
5+
workflow_run:
6+
workflows: ["Create PR Checklist"]
7+
types:
8+
- completed
9+
10+
# Alternative trigger if you want to directly react to comment edits (optional)
11+
issue_comment:
12+
types: [edited]
13+
14+
permissions:
15+
pull-requests: read
16+
statuses: write
17+
issues: read
18+
19+
jobs:
20+
update-status:
21+
runs-on: ubuntu-latest
22+
if: github.event.issue.pull_request
23+
steps:
24+
- name: Update commit statuses based on checklist
25+
uses: actions/github-script@v6
26+
with:
27+
script: |
28+
const pr = await github.rest.pulls.get({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
pull_number: context.issue.number,
32+
});
33+
34+
const sha = pr.data.head.sha;
35+
const body = context.payload.comment.body;
36+
37+
const checklist = [
38+
{ key: "internal-ticket", context: "Create an internal ticket" },
39+
{ key: "view-testing", context: "Complete view testing" },
40+
];
41+
42+
for (const item of checklist) {
43+
const regex = new RegExp(`- \\[x\\] .*${item.context}`, "i");
44+
const isChecked = regex.test(body);
45+
const state = isChecked ? "success" : "pending";
46+
47+
await github.rest.repos.createCommitStatus({
48+
owner: context.repo.owner,
49+
repo: context.repo.repo,
50+
sha,
51+
state,
52+
context: item.context,
53+
description: isChecked
54+
? "Completed via checklist"
55+
: "Awaiting manual approval via checklist",
56+
});
57+
}

.github/workflows/pr-watcher.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: 'Create PR Checklist'
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
6+
permissions:
7+
pull-requests: write
8+
statuses: write
9+
issues: write # needed to add labels
10+
contents: read # needed to get collaborators
11+
12+
jobs:
13+
setup:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check if PR author is a maintainer
17+
id: check_maintainer
18+
uses: actions/github-script@v6
19+
with:
20+
script: |
21+
// Fetch the PR author
22+
const prUser = context.payload.pull_request.user.login;
23+
console.log(`PR author: ${prUser}`);
24+
25+
// Check if author is a collaborator (maintainer)
26+
try {
27+
const { status } = await github.rest.repos.checkCollaborator({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
username: prUser,
31+
});
32+
console.log(`Collaborator check status: ${status}`);
33+
console.log(`${prUser} is a maintainer.`);
34+
core.setOutput("is_maintainer", true);
35+
} catch (error) {
36+
if (error.status === 404) {
37+
console.log(`${prUser} is NOT a maintainer.`);
38+
core.setOutput("is_maintainer", false);
39+
} else {
40+
console.log(`Error checking collaborator: ${error}`);
41+
throw error;
42+
}
43+
}
44+
45+
46+
- name: Add labels
47+
#if: steps.check_maintainer.outputs.is_maintainer == 'false'
48+
uses: actions/github-script@v6
49+
with:
50+
script: |
51+
await github.rest.issues.addLabels({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
issue_number: context.payload.pull_request.number,
55+
labels: ['community']
56+
});
57+
58+
- name: Create pending statuses
59+
#if: steps.check_maintainer.outputs.is_maintainer == 'false'
60+
uses: actions/github-script@v6
61+
with:
62+
script: |
63+
const checklist = [
64+
{ key: "internal-ticket", context: "Create an internal ticket" },
65+
{ key: "view-testing", context: "Complete view testing" },
66+
];
67+
for (const item of checklist) {
68+
await github.rest.repos.createCommitStatus({
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
sha: context.payload.pull_request.head.sha,
72+
state: 'pending',
73+
context: item.context,
74+
description: 'Awaiting manual approval via checklist',
75+
});
76+
}
77+
78+
- name: Create PR checklist comment
79+
#if: steps.check_maintainer.outputs.is_maintainer == 'false'
80+
uses: wadackel/checkbox-workflow-action@v1
81+
with:
82+
id: pr-checklist
83+
number: ${{ github.event.pull_request.number }}
84+
config: |
85+
[
86+
{"internal-ticket": "Create an internal ticket"},
87+
{"view-testing": "Complete view testing"}
88+
]
89+
message: |
90+
## PR Checklist
91+
{{body}}

0 commit comments

Comments
 (0)