forked from lightningpixel/modly
-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (138 loc) · 6.19 KB
/
Copy pathassign-command.yml
File metadata and controls
157 lines (138 loc) · 6.19 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Assign command
on:
issue_comment:
types: [created]
permissions:
issues: write
env:
PROJECT_ID: PVT_kwHOA8O2Dc4BX1OY
STATUS_FIELD_ID: PVTSSF_lAHOA8O2Dc4BX1OYzhS_ZbU
STATUS_IN_PROGRESS: "98236657"
STATUS_BACKLOG: "f75ad846"
jobs:
assign:
if: ${{ !github.event.issue.pull_request && (github.event.comment.body == '/assign' || github.event.comment.body == '/unassign') }}
runs-on: ubuntu-latest
steps:
- name: Handle /assign
id: do_assign
if: github.event.comment.body == '/assign'
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const commenter = context.payload.comment.user.login;
const { data: issue } = await github.rest.issues.get({ owner, repo, issue_number });
if (issue.assignees.length > 0) {
const names = issue.assignees.map(a => `@${a.login}`).join(', ');
await github.rest.issues.createComment({
owner, repo, issue_number,
body: `⚠️ This issue is already assigned to ${names}. Ask them to comment \`/unassign\` first if they're no longer working on it.`,
});
core.setOutput('assigned', 'false');
return;
}
await github.rest.issues.addAssignees({ owner, repo, issue_number, assignees: [commenter] });
await github.rest.issues.createComment({
owner, repo, issue_number,
body: `✅ Assigned to @${commenter}. Comment \`/unassign\` if you can no longer work on this. Open a PR that includes \`Closes #${issue_number}\` in its description when you're ready for review.`,
});
core.setOutput('assigned', 'true');
- name: Move to In progress
if: github.event.comment.body == '/assign' && steps.do_assign.outputs.assigned == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.PROJECT_TOKEN }}
script: |
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number,
});
const { node } = await github.graphql(
`query($issueId: ID!) {
node(id: $issueId) {
... on Issue { projectItems(first: 10) { nodes { id project { id } } } }
}
}`,
{ issueId: issue.node_id }
);
const item = node.projectItems.nodes.find(n => n.project.id === process.env.PROJECT_ID);
if (!item) {
console.log('Issue is not on the project board; skipping status update.');
return;
}
await github.graphql(
`mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $projectId, itemId: $itemId, fieldId: $fieldId,
value: { singleSelectOptionId: $optionId }
}) { projectV2Item { id } }
}`,
{
projectId: process.env.PROJECT_ID,
itemId: item.id,
fieldId: process.env.STATUS_FIELD_ID,
optionId: process.env.STATUS_IN_PROGRESS,
}
);
- name: Handle /unassign
id: do_unassign
if: github.event.comment.body == '/unassign'
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const commenter = context.payload.comment.user.login;
const { data: issue } = await github.rest.issues.get({ owner, repo, issue_number });
const isAssigned = issue.assignees.some(a => a.login === commenter);
if (!isAssigned) {
await github.rest.issues.createComment({
owner, repo, issue_number,
body: `⚠️ @${commenter}, you're not currently assigned to this issue.`,
});
core.setOutput('unassigned', 'false');
return;
}
await github.rest.issues.removeAssignees({ owner, repo, issue_number, assignees: [commenter] });
await github.rest.issues.createComment({
owner, repo, issue_number,
body: `Unassigned @${commenter}. This issue is open again — comment \`/assign\` to pick it up.`,
});
core.setOutput('unassigned', 'true');
- name: Move to Backlog
if: github.event.comment.body == '/unassign' && steps.do_unassign.outputs.unassigned == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.PROJECT_TOKEN }}
script: |
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number,
});
const { node } = await github.graphql(
`query($issueId: ID!) {
node(id: $issueId) {
... on Issue { projectItems(first: 10) { nodes { id project { id } } } }
}
}`,
{ issueId: issue.node_id }
);
const item = node.projectItems.nodes.find(n => n.project.id === process.env.PROJECT_ID);
if (!item) {
console.log('Issue is not on the project board; skipping status update.');
return;
}
await github.graphql(
`mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $projectId, itemId: $itemId, fieldId: $fieldId,
value: { singleSelectOptionId: $optionId }
}) { projectV2Item { id } }
}`,
{
projectId: process.env.PROJECT_ID,
itemId: item.id,
fieldId: process.env.STATUS_FIELD_ID,
optionId: process.env.STATUS_BACKLOG,
}
);