-
Notifications
You must be signed in to change notification settings - Fork 207
64 lines (55 loc) · 2.12 KB
/
label-community-issues.yml
File metadata and controls
64 lines (55 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: Label Community Issues
on:
issues:
types: [opened]
jobs:
label-community-issues:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
# Adding this step for debug purposes
# If this works as expected, we can simplify this workflow
# and replace it with the `check-membership` step
- name: Check organization membership (test)
run: echo "${{ github.event.issue.author_association == 'MEMBER' }}"
- name: Check organization membership
id: check-membership
uses: actions/github-script@v7
with:
github-token: ${{ secrets.ORG_MEMBER_READ_TOKEN }}
result-encoding: string
script: |
const issueAuthor = '${{ github.event.issue.user.login }}';
const orgName = 'elastic';
try {
await github.rest.orgs.getMembershipForUser({
org: orgName,
username: issueAuthor
});
console.log(`${issueAuthor} is a member of ${orgName} organization`);
return 'member';
} catch (error) {
if (error.status === 404) {
console.log(`${issueAuthor} is not a member of ${orgName} organization`);
return 'non-member';
} else {
console.log('Error checking organization membership:', error);
return 'error';
}
}
- name: Add community label
if: steps.check-membership.outputs.result == 'non-member'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueAuthor = '${{ github.event.issue.user.login }}';
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['community']
});
console.log(`Added "community" label to issue by ${issueAuthor}`);