|
1 | 1 | name: 'Create PR Checklist' |
2 | 2 | on: |
3 | | - pull_request_target: |
| 3 | + pull_request: |
4 | 4 | types: [opened, synchronize, reopened] |
5 | 5 |
|
6 | 6 | permissions: |
7 | 7 | pull-requests: write |
8 | 8 | statuses: write |
9 | 9 | issues: write # needed to add labels |
10 | 10 | contents: read # needed to get collaborators |
11 | | - |
12 | | -# Security guidelines |
13 | | -# Do not checkout code from the PR |
14 | | -# Do not run scripts or commands from the PR |
| 11 | + members: read # needed to check team membership |
15 | 12 |
|
16 | 13 | jobs: |
17 | 14 | setup: |
18 | 15 | runs-on: ubuntu-latest |
19 | 16 | steps: |
20 | | - - name: Check if PR author is a maintainer |
21 | | - id: check_maintainer |
| 17 | + - name: Check if PR author is a team member |
| 18 | + id: check_team_member |
22 | 19 | uses: actions/github-script@v6 |
23 | 20 | with: |
24 | 21 | script: | |
25 | | - // Fetch the PR author |
26 | 22 | const prUser = context.payload.pull_request.user.login; |
27 | 23 | console.log(`PR author: ${prUser}`); |
28 | 24 |
|
29 | | - // Check if author is a collaborator (maintainer) |
30 | | - try { |
31 | | - const { status } = await github.rest.repos.checkCollaborator({ |
32 | | - owner: context.repo.owner, |
33 | | - repo: context.repo.repo, |
34 | | - username: prUser, |
35 | | - }); |
36 | | - console.log(`Collaborator check status: ${status}`); |
37 | | - console.log(`${prUser} is a maintainer.`); |
38 | | - core.setOutput("is_maintainer", true); |
39 | | - } catch (error) { |
40 | | - if (error.status === 404) { |
41 | | - console.log(`${prUser} is NOT a maintainer.`); |
42 | | - core.setOutput("is_maintainer", false); |
43 | | - } else { |
44 | | - console.log(`Error checking collaborator: ${error}`); |
45 | | - throw error; |
| 25 | + // List of team slugs to check (update these with your actual team names) |
| 26 | + const teamSlugs = ['rvos-committers']; |
| 27 | + |
| 28 | + let isTeamMember = false; |
| 29 | +
|
| 30 | + // Check if author is a member of any of the specified teams |
| 31 | + for (const teamSlug of teamSlugs) { |
| 32 | + try { |
| 33 | + await github.rest.teams.getMembershipForUserInOrg({ |
| 34 | + org: context.repo.owner, |
| 35 | + team_slug: teamSlug, |
| 36 | + username: prUser, |
| 37 | + }); |
| 38 | + console.log(`${prUser} is a member of team: ${teamSlug}`); |
| 39 | + isTeamMember = true; |
| 40 | + break; |
| 41 | + } catch (error) { |
| 42 | + if (error.status === 404) { |
| 43 | + console.log(`${prUser} is NOT a member of team: ${teamSlug}`); |
| 44 | + } else { |
| 45 | + console.log(`Error checking team membership for ${teamSlug}: ${error.message}`); |
| 46 | + } |
46 | 47 | } |
47 | 48 | } |
48 | 49 | |
| 50 | + core.setOutput("is_team_member", isTeamMember); |
| 51 | + console.log(`Final result - is_team_member: ${isTeamMember}`); |
49 | 52 | |
50 | | - - name: Add labels |
51 | | - #if: steps.check_maintainer.outputs.is_maintainer == 'false' |
| 53 | + |
| 54 | + - name: Add community label |
| 55 | + if: steps.check_team_member.outputs.is_team_member == 'false' |
52 | 56 | uses: actions/github-script@v6 |
53 | 57 | with: |
54 | 58 | script: | |
|
59 | 63 | labels: ['community'] |
60 | 64 | }); |
61 | 65 | |
62 | | - - name: Create pending statuses |
63 | | - #if: steps.check_maintainer.outputs.is_maintainer == 'false' |
| 66 | + - name: Create pending statuses for community PRs |
| 67 | + if: steps.check_team_member.outputs.is_team_member == 'false' |
64 | 68 | uses: actions/github-script@v6 |
65 | 69 | with: |
66 | 70 | script: | |
|
79 | 83 | }); |
80 | 84 | } |
81 | 85 | |
82 | | - - name: Create PR checklist comment |
83 | | - #if: steps.check_maintainer.outputs.is_maintainer == 'false' |
| 86 | + - name: Auto-approve statuses for team member PRs |
| 87 | + if: steps.check_team_member.outputs.is_team_member == 'true' |
| 88 | + uses: actions/github-script@v6 |
| 89 | + with: |
| 90 | + script: | |
| 91 | + const checklist = [ |
| 92 | + { key: "internal-ticket", context: "Create an internal ticket" }, |
| 93 | + { key: "view-testing", context: "Complete view testing" }, |
| 94 | + ]; |
| 95 | + for (const item of checklist) { |
| 96 | + await github.rest.repos.createCommitStatus({ |
| 97 | + owner: context.repo.owner, |
| 98 | + repo: context.repo.repo, |
| 99 | + sha: context.payload.pull_request.head.sha, |
| 100 | + state: 'success', |
| 101 | + context: item.context, |
| 102 | + description: 'Auto-approved for team member', |
| 103 | + }); |
| 104 | + } |
| 105 | + |
| 106 | + - name: Create PR checklist comment for community PRs |
| 107 | + if: steps.check_team_member.outputs.is_team_member == 'false' |
84 | 108 | uses: wadackel/checkbox-workflow-action@v1 |
85 | 109 | with: |
86 | 110 | id: pr-checklist |
|
0 commit comments