Skip to content

Commit c0ddcf3

Browse files
authored
Add auto-assign-on-comment.yml (#20)
Signed-off-by: Shingo OKAWA <[email protected]>
1 parent 6f94853 commit c0ddcf3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Auto Assign on 'take' Comment
2+
on:
3+
issue_comment:
4+
types: [created]
5+
permissions:
6+
issues: write
7+
jobs:
8+
assign:
9+
runs-on:
10+
group: databrickslabs-protected-runner-group
11+
labels: linux-ubuntu-latest
12+
if: (!github.event.issue.pull_request) && contains(github.event.comment.body, 'take')
13+
concurrency:
14+
group: ${{ github.actor }}-auto-assign-issue
15+
cancel-in-progress: true
16+
steps:
17+
- name: Auto assign if comment includes 'take'
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
const body = context.payload.comment.body.toLowerCase();
22+
const author = context.payload.comment.user.login;
23+
const issue = context.payload.issue;
24+
25+
// Check if comment includes 'take'
26+
if (!body.includes('take')) {
27+
console.log("Comment does not include 'take'; skipping.");
28+
return;
29+
}
30+
31+
// Check if already assigned
32+
const alreadyAssigned = issue.assignees.find(a => a.login === author);
33+
if (alreadyAssigned) {
34+
console.log(`${author} is already assigned; skipping.`);
35+
return;
36+
}
37+
38+
// Check if there is any other assignee
39+
if (issue.assignees.length > 0) {
40+
console.log("Issue already has an assignee; skipping assignment.");
41+
return;
42+
}
43+
44+
// Assign to commenter
45+
await github.rest.issues.addAssignees({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
issue_number: issue.number,
49+
assignees: [author],
50+
});
51+
52+
console.log(`Assigned ${author} to issue #${issue.number}`);

0 commit comments

Comments
 (0)