Skip to content

Commit bfd252b

Browse files
authored
Merge pull request #161 from NawinKumarSharma/github-workflow
chore: Add a /assign to automatically assign the issue
2 parents cde5f12 + ceccad0 commit bfd252b

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/repo-management.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Repository Management
2+
3+
on:
4+
issues:
5+
types: [opened, reopened, edited]
6+
pull_request:
7+
types: [opened, reopened, edited]
8+
issue_comment:
9+
types: [created]
10+
11+
jobs:
12+
manage_repo:
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Handle /assign command
17+
if: github.event_name == 'issue_comment' && github.event.action == 'created'
18+
uses: actions/github-script@v6
19+
with:
20+
github-token: ${{secrets.MY_GITHUB_TOKEN}}
21+
script: |
22+
const { owner, repo } = context.repo;
23+
const comment = context.payload.comment;
24+
const issueNumber = context.payload.issue.number;
25+
26+
if (comment.body.trim().toLowerCase() === '/assign') {
27+
const issue = await github.rest.issues.get({
28+
owner,
29+
repo,
30+
issue_number: issueNumber
31+
});
32+
33+
if (!issue.data.assignee) {
34+
await github.rest.issues.addAssignees({
35+
owner,
36+
repo,
37+
issue_number: issueNumber,
38+
assignees: [comment.user.login]
39+
});
40+
41+
await github.rest.issues.createComment({
42+
owner,
43+
repo,
44+
issue_number: issueNumber,
45+
body: `@${comment.user.login} has been assigned to this issue.`
46+
});
47+
} else {
48+
await github.rest.issues.createComment({
49+
owner,
50+
repo,
51+
issue_number: issueNumber,
52+
body: 'This issue is already assigned. Please choose an unassigned issue.'
53+
});
54+
}
55+
}

0 commit comments

Comments
 (0)