Skip to content

Commit fedf202

Browse files
committed
chore: add contributor label for callstack-internal org
1 parent 526af2b commit fedf202

1 file changed

Lines changed: 43 additions & 15 deletions

File tree

‎.github/workflows/contributor-label.yml‎

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,74 @@ on:
66

77
permissions:
88
issues: write
9-
pull-requests: write
109

1110
jobs:
1211
label:
1312
name: Add contributor label
1413
runs-on: ubuntu-latest
1514
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+
1623
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
24+
env:
25+
ORG_MEMBERSHIP_TOKEN: ${{ steps.app-token.outputs.token }}
1726
with:
1827
github-token: ${{ secrets.GITHUB_TOKEN }}
1928
script: |
2029
const owner = context.repo.owner;
2130
const repo = context.repo.repo;
2231
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;
2441
25-
try {
26-
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
42+
const { data } =
43+
await github.rest.repos.getCollaboratorPermissionLevel({
2744
owner,
2845
repo,
29-
username: context.payload.pull_request.user.login,
46+
username,
3047
});
3148
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+
}
3667
}
3768
}
3869
39-
if (
40-
!['MEMBER', 'OWNER'].includes(context.payload.pull_request.author_association) &&
41-
!['admin', 'maintain', 'write'].includes(permission)
42-
) {
70+
if (!isInternal) {
4371
return;
4472
}
4573
4674
await github.rest.issues.addLabels({
4775
owner,
4876
repo,
49-
issue_number: context.issue.number,
50-
labels: ['Contributor: Internal'],
77+
issue_number: pullRequest.number,
78+
labels: [label],
5179
});

0 commit comments

Comments
 (0)