-
Notifications
You must be signed in to change notification settings - Fork 1
50 lines (45 loc) · 1.77 KB
/
Copy pathbot.yml
File metadata and controls
50 lines (45 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: unic-bot
on:
issue_comment:
types: [created]
jobs:
handle-command:
if: contains(github.event.comment.body, '@unic-bot')
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Handle bot command
uses: actions/github-script@v7
with:
script: |
const body = context.payload.comment.body;
const commenter = context.payload.comment.user.login;
const issue = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
// Extract command after "@unic-bot:"
const match = body.match(/@unic-bot:\s*(.+)/i);
if (!match) {
await github.rest.issues.createComment({
owner, repo, issue_number: issue,
body: `@${commenter} I didn't understand that. Usage: \`@unic-bot: <command>\`\n\nAvailable commands:\n- \`assign me\` — assign this issue to yourself`,
});
return;
}
const command = match[1].trim().toLowerCase();
if (command === 'assign me') {
await github.rest.issues.addAssignees({
owner, repo, issue_number: issue,
assignees: [commenter],
});
await github.rest.issues.createComment({
owner, repo, issue_number: issue,
body: `@${commenter} has been assigned to this issue.`,
});
} else {
await github.rest.issues.createComment({
owner, repo, issue_number: issue,
body: `@${commenter} Unknown command: \`${command}\`\n\nAvailable commands:\n- \`assign me\` — assign this issue to yourself`,
});
}