Skip to content

Commit 44dfcd3

Browse files
committed
[Wofkflow] Add "needs-triage" to new issues
The focus of these changes is to introduce a new GitHub Actions workflow that automatically labels new issues with `needs-triage`. New issues are not labeled if: - The issue is created by someone with write permissions - The issue is created with a set of labels
1 parent 01d6d76 commit 44dfcd3

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.github/workflows/needs-triage.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
name: Add needs-triage label
3+
4+
'on':
5+
issues:
6+
types: [opened]
7+
8+
jobs:
9+
add-needs-triage:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: write
13+
repository-projects: read
14+
steps:
15+
- name: Check if issue already has labels
16+
id: check-labels
17+
uses: actions/github-script@v7
18+
with:
19+
script: |
20+
const issue = context.payload.issue;
21+
const hasLabels = issue.labels && issue.labels.length > 0;
22+
core.setOutput('has-labels', hasLabels);
23+
return hasLabels;
24+
25+
- name: Check if author has write permissions
26+
id: check-permissions
27+
if: steps.check-labels.outputs.has-labels == 'false'
28+
uses: actions/github-script@v7
29+
with:
30+
script: |
31+
const issue = context.payload.issue;
32+
const author = issue.user.login;
33+
34+
try {
35+
const { data: permission } = await github.rest.repos
36+
.getCollaboratorPermissionLevel({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
username: author
40+
});
41+
42+
const hasWriteAccess = ['write', 'admin', 'maintain']
43+
.includes(permission.permission);
44+
core.setOutput('has-write-access', hasWriteAccess);
45+
return hasWriteAccess;
46+
} catch (error) {
47+
// If user is not a collaborator, they don't have write access
48+
core.setOutput('has-write-access', false);
49+
return false;
50+
}
51+
52+
- name: Add needs-triage label
53+
if: >-
54+
steps.check-labels.outputs.has-labels == 'false' &&
55+
steps.check-permissions.outputs.has-write-access == 'false'
56+
uses: actions/github-script@v7
57+
with:
58+
script: |
59+
await github.rest.issues.addLabels({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
issue_number: context.payload.issue.number,
63+
labels: ['needs-triage']
64+
});

0 commit comments

Comments
 (0)