Skip to content

Commit f31413c

Browse files
[Github Action] Label community issues (#1746)
_Generated with Copilot_ This is an attempt to identify community (from non-elasticians) issues more accurately rather than rely only on `source:web` label or on the triager checking the issue author's profile every time.
1 parent eac2961 commit f31413c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Label Community Issues
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
label-community-issues:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
issues: write
12+
contents: read
13+
14+
steps:
15+
- name: Check organization membership
16+
id: check-membership
17+
uses: actions/github-script@v7
18+
with:
19+
github-token: ${{ secrets.ORG_MEMBER_READ_TOKEN }}
20+
script: |
21+
const issueAuthor = '${{ github.event.issue.user.login }}';
22+
const orgName = 'elastic';
23+
24+
try {
25+
await github.rest.orgs.getMembershipForUser({
26+
org: orgName,
27+
username: issueAuthor
28+
});
29+
30+
console.log(`${issueAuthor} is a member of ${orgName} organization`);
31+
return 'member';
32+
33+
} catch (error) {
34+
if (error.status === 404) {
35+
console.log(`${issueAuthor} is not a member of ${orgName} organization`);
36+
return 'non-member';
37+
} else {
38+
console.log('Error checking organization membership:', error);
39+
return 'error';
40+
}
41+
}
42+
43+
- name: Add community label
44+
if: steps.check-membership.outputs.result == 'non-member'
45+
uses: actions/github-script@v7
46+
with:
47+
github-token: ${{ secrets.GITHUB_TOKEN }}
48+
script: |
49+
const issueAuthor = '${{ github.event.issue.user.login }}';
50+
51+
await github.rest.issues.addLabels({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
issue_number: context.issue.number,
55+
labels: ['community']
56+
});
57+
58+
console.log(`Added "community" label to issue by ${issueAuthor}`);

0 commit comments

Comments
 (0)