Skip to content

Commit de9bef9

Browse files
authored
Add auto-assign-on-comment.yaml (databrickslabs#14)
Signed-off-by: Shingo OKAWA <[email protected]>
1 parent df75a27 commit de9bef9

File tree

1 file changed

+50
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)