-
Notifications
You must be signed in to change notification settings - Fork 9
58 lines (51 loc) · 2.36 KB
/
selfAssign.yml
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
51
52
53
54
55
56
57
58
name: Self Assign Issue
on:
issue_comment:
types:
- created
jobs:
assign:
runs-on: ubuntu-latest
steps:
- name: Check for command
id: find_command
uses: actions/github-script@v4
with:
github-token: ${{ secrets.MY_TOKEN }}
script: |
const commentBody = context.payload.comment.body;
const assignUsing = '/assignme';
const commenter = context.payload.comment.user.login;
const issueAssignees = context.payload.issue.assignees.map(assignee => assignee.login);
const hasAssignees = issueAssignees.length > 0;
console.log(`Comment Body: ${commentBody}`);
console.log(`Command Present: ${commentBody.includes(assignUsing)}`);
console.log(`Commenter: ${commenter}`);
console.log(`Current Assignees: ${issueAssignees}`);
if (!commentBody.includes(assignUsing)) {
console.log('Command not present, nothing to do');
return core.setOutput('toAssign', 'false');
}
if (hasAssignees && issueAssignees.includes(commenter)) {
console.log('Issue is already assigned to the commenter.');
return core.setOutput('toAssign', 'false');
}
if (hasAssignees) {
console.log('Issue is already assigned to someone else.');
const { owner, repo, number } = context.issue;
const body = `Hey @${commenter}, the issue is already assigned to someone else. Feel free to work on another issue or create a new one! 😥`;
await github.issues.createComment({ owner, repo, issue_number: number, body });
return core.setOutput('toAssign', 'false');
}
console.log('Assigning the issue to the commenter.');
core.setOutput('toAssign', 'true');
- name: Assign the issue
if: steps.find_command.outputs.toAssign == 'true'
uses: actions/github-script@v4
with:
github-token: ${{ secrets.MY_TOKEN }}
script: |
const { owner, repo, number } = context.issue;
const assignee = context.payload.comment.user.login;
await github.issues.addAssignees({ owner, repo, issue_number: number, assignees: [assignee] });
console.log(`Assigned the issue to ${assignee}.`);