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