Skip to content

Commit 43c1e7c

Browse files
authored
feat(workflow): introduce slash-command based issue triage (#511)
1 parent d743430 commit 43c1e7c

2 files changed

Lines changed: 178 additions & 0 deletions

File tree

.github/scripts/triageIssue.js

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
module.exports = async({github, context}) => {
2+
const owner = context.repo.owner;
3+
const repo = context.repo.repo;
4+
const issue = context.payload.issue;
5+
const issueNumber = issue.number;
6+
const issueDescription = issue.body;
7+
const username = issue.user.login
8+
9+
if(context.eventName === 'issues'){
10+
try {
11+
if(!issueDescription || !issueDescription.trim()){
12+
return await github.rest.issues.createComment({
13+
owner,
14+
repo,
15+
issue_number: issueNumber,
16+
body: `Hi @${username},
17+
18+
Thanks for opening this issue.
19+
20+
It looks like the issue description is currently missing.
21+
22+
Please provide:
23+
- A brief summary of the problem
24+
- Expected behavior
25+
- Actual behavior (if applicable)
26+
- Any relevant screenshots, logs, or context
27+
28+
This helps the team understand, prioritize, and route the issue correctly.
29+
30+
Thank you!
31+
32+
`
33+
})
34+
}
35+
36+
return await github.rest.issues.createComment({
37+
owner,
38+
repo,
39+
issue_number: issueNumber,
40+
body: `Hi @${username},
41+
42+
Thanks for opening this issue.
43+
44+
Please reply with one of the following areas so the issue can be routed to the appropriate team member:
45+
46+
- /backend
47+
- /web
48+
- /mobile
49+
- /devops
50+
51+
Once an area is selected, the corresponding label will be added automatically.`
52+
})
53+
54+
} catch (error) {
55+
console.error(error)
56+
}
57+
}else if(context.eventName === 'issue_comment'){
58+
if (context.payload.comment.user.type === 'Bot' || context.payload.comment.user.login === 'github-actions[bot]') {
59+
return;
60+
}
61+
62+
const comment = (context.payload.comment.body || '').trim().toLowerCase();
63+
const existingLabels = (issue.labels || []).map(label => label.name);
64+
65+
if (
66+
existingLabels.includes('backend') ||
67+
existingLabels.includes('web') ||
68+
existingLabels.includes('mobile') ||
69+
existingLabels.includes('devops')
70+
) {
71+
return;
72+
}
73+
74+
if (!['/backend', '/web', '/mobile', '/devops'].includes(comment)) {
75+
return;
76+
}
77+
if(comment === '/backend'){
78+
await github.rest.issues.addLabels({
79+
owner,
80+
repo,
81+
issue_number: issueNumber,
82+
labels: ['backend']
83+
84+
})
85+
return await github.rest.issues.createComment({
86+
owner,
87+
repo,
88+
issue_number: issueNumber,
89+
body: `The issue has been classified as **backend**.
90+
91+
@Harxhit, please review and triage this issue when available.
92+
93+
The **backend** label has been applied and the issue has been routed accordingly.`
94+
})
95+
}else if(comment === '/web'){
96+
await github.rest.issues.addLabels({
97+
owner,
98+
repo,
99+
issue_number: issueNumber,
100+
labels: ['web']
101+
102+
})
103+
return await github.rest.issues.createComment({
104+
owner,
105+
repo,
106+
issue_number: issueNumber,
107+
body: `The issue has been classified as **web**.
108+
109+
@ShantKhatri, please review and triage this issue when available.
110+
111+
The **web** label has been applied and the issue has been routed accordingly.`
112+
})
113+
}else if(comment === '/mobile'){
114+
await github.rest.issues.addLabels({
115+
owner,
116+
repo,
117+
issue_number: issueNumber,
118+
labels: ['mobile']
119+
120+
})
121+
return await github.rest.issues.createComment({
122+
owner,
123+
repo,
124+
issue_number: issueNumber,
125+
body: `The issue has been classified as **mobile**.
126+
127+
@blankirigaya, please review and triage this issue when available.
128+
129+
The **mobile** label has been applied and the issue has been routed accordingly.`
130+
})
131+
}else if(comment === '/devops'){
132+
await github.rest.issues.addLabels({
133+
owner,
134+
repo,
135+
issue_number: issueNumber,
136+
labels: ['devops']
137+
138+
})
139+
return await github.rest.issues.createComment({
140+
owner,
141+
repo,
142+
issue_number: issueNumber,
143+
body: `The issue has been classified as **devops**.
144+
145+
@ShantKhatri, please review and triage this issue when available.
146+
147+
The **devops** label has been applied and the issue has been routed accordingly.`
148+
})
149+
}
150+
}
151+
}

.github/workflows/triageIssue.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Issue triage
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
issue_comment:
7+
types: [created, edited]
8+
9+
10+
permissions:
11+
issues: write
12+
13+
jobs:
14+
assignLabel:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
20+
21+
- name: Triage issue
22+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #v9.0.0
23+
with:
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
script: |
26+
const script = require('./.github/scripts/triageIssue.js');
27+
await script({ github, context });

0 commit comments

Comments
 (0)