|
6 | 6 |
|
7 | 7 | permissions: |
8 | 8 | issues: write |
9 | | - pull-requests: write |
10 | 9 |
|
11 | 10 | jobs: |
12 | 11 | label: |
13 | 12 | name: Add contributor label |
14 | 13 | runs-on: ubuntu-latest |
15 | 14 | steps: |
| 15 | + - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 |
| 16 | + id: app-token |
| 17 | + with: |
| 18 | + app-id: ${{ secrets.ORG_MEMBERSHIP_APP_ID }} |
| 19 | + private-key: ${{ secrets.ORG_MEMBERSHIP_APP_PRIVATE_KEY }} |
| 20 | + owner: callstack-internal |
| 21 | + permission-members: read |
| 22 | + |
16 | 23 | - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 24 | + env: |
| 25 | + ORG_MEMBERSHIP_TOKEN: ${{ steps.app-token.outputs.token }} |
17 | 26 | with: |
18 | 27 | github-token: ${{ secrets.GITHUB_TOKEN }} |
19 | 28 | script: | |
20 | 29 | const owner = context.repo.owner; |
21 | 30 | const repo = context.repo.repo; |
22 | 31 |
|
23 | | - let permission = 'none'; |
| 32 | + const label = 'Contributor: Internal'; |
| 33 | +
|
| 34 | + const pullRequest = context.payload.pull_request; |
| 35 | +
|
| 36 | + if (pullRequest.labels.some(({ name }) => name === label)) { |
| 37 | + return; |
| 38 | + } |
| 39 | +
|
| 40 | + const username = pullRequest.user.login; |
24 | 41 |
|
25 | | - try { |
26 | | - const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 42 | + const { data } = |
| 43 | + await github.rest.repos.getCollaboratorPermissionLevel({ |
27 | 44 | owner, |
28 | 45 | repo, |
29 | | - username: context.payload.pull_request.user.login, |
| 46 | + username, |
30 | 47 | }); |
31 | 48 |
|
32 | | - permission = data.permission; |
33 | | - } catch (error) { |
34 | | - if (error.status !== 404) { |
35 | | - throw error; |
| 49 | + let isInternal = |
| 50 | + ['MEMBER', 'OWNER'].includes(pullRequest.author_association) || |
| 51 | + ['admin', 'maintain', 'write'].includes(data.permission); |
| 52 | +
|
| 53 | + if (!isInternal) { |
| 54 | + try { |
| 55 | + const internalGithub = getOctokit(process.env.ORG_MEMBERSHIP_TOKEN); |
| 56 | +
|
| 57 | + await internalGithub.rest.orgs.checkMembershipForUser({ |
| 58 | + org: 'callstack-internal', |
| 59 | + username, |
| 60 | + }); |
| 61 | +
|
| 62 | + isInternal = true; |
| 63 | + } catch (error) { |
| 64 | + if (error.status !== 404) { |
| 65 | + throw error; |
| 66 | + } |
36 | 67 | } |
37 | 68 | } |
38 | 69 |
|
39 | | - if ( |
40 | | - !['MEMBER', 'OWNER'].includes(context.payload.pull_request.author_association) && |
41 | | - !['admin', 'maintain', 'write'].includes(permission) |
42 | | - ) { |
| 70 | + if (!isInternal) { |
43 | 71 | return; |
44 | 72 | } |
45 | 73 |
|
46 | 74 | await github.rest.issues.addLabels({ |
47 | 75 | owner, |
48 | 76 | repo, |
49 | | - issue_number: context.issue.number, |
50 | | - labels: ['Contributor: Internal'], |
| 77 | + issue_number: pullRequest.number, |
| 78 | + labels: [label], |
51 | 79 | }); |
0 commit comments