-
Notifications
You must be signed in to change notification settings - Fork 27
59 lines (54 loc) · 2.63 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
59
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_SEC}}
script: |
const commentBody = context.payload.comment.body;
const assignUsing = '/assignme';
const isCommandPresent = commentBody.includes(assignUsing);
const commenter = context.payload.comment.user.login;
const isSelf = commenter === 'Puskar-Roy';
const hasAssignees = context.payload.issue.assignees.length > 0;
console.log(`Comment Body: ${commentBody}`);
console.log(`Command Present: ${isCommandPresent}`);
console.log(`Commenter: ${commenter}`);
console.log(`Is Self: ${isSelf}`);
console.log(`Assignees: ${context.payload.issue.assignees.map(assignee => assignee.login)}`);
if (isCommandPresent && isSelf) {
console.log('Command present in comment by self, ignoring');
console.log('::set-output name=toAssign::false');
} else if (isCommandPresent && hasAssignees) {
console.log('Command present, issue already assigned');
const { owner, repo, number } = context.issue;
const commentBody = `Hey @${commenter}, the issue has already been assigned and cannot be assigned to you again. Feel free to work on another issue or create a new one.😥
`;
github.issues.createComment({ owner, repo, issue_number: number, body: commentBody });
console.log('::set-output name=toAssign::false');
} else if (isCommandPresent) {
console.log('Command present, assigning the issue');
console.log('::set-output name=toAssign::true');
} else {
console.log('Command not present, nothing to do');
console.log('::set-output name=toAssign::false');
}
- name: Assign the issue
if: steps.find_command.outputs.toAssign == 'true'
id: assign_issue
uses: actions/github-script@v4
with:
github-token: ${{ secrets.MY_SEC}}
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}.`);