-
-
Notifications
You must be signed in to change notification settings - Fork 1
237 lines (221 loc) · 8.33 KB
/
project-auto-status.yml
File metadata and controls
237 lines (221 loc) · 8.33 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# Auto-update Project #6 status when PRs merge or issues close.
#
# - PR merged → linked issues + PR move to "Done"
# - Issue closed → move to "Done"
# - PR opened → move to "In review"
#
# Requires PROJECT_TOKEN secret (classic PAT with `project` scope).
name: Auto-update Project Status
on:
issues:
types: [closed, labeled]
pull_request:
types: [opened, closed]
env:
PROJECT_ID: PVT_kwHOAGdgHc4A-axm
STATUS_FIELD_ID: PVTSSF_lAHOAGdgHc4A-axmzgx076o
DONE_OPTION_ID: "98236657"
IN_REVIEW_OPTION_ID: aba860b9
IN_PROGRESS_OPTION_ID: "47fc9ee4"
jobs:
# When an issue gets agent:spawn label → set "In Progress"
agent-started:
if: github.event_name == 'issues' && github.event.action == 'labeled' && github.event.label.name == 'agent:spawn'
runs-on: ubuntu-latest
steps:
- name: Get project item ID
id: get-item
env:
GH_TOKEN: ${{ secrets.PROJECT_TOKEN }}
run: |
ITEM_ID=$(gh api graphql -f query='
query($url: URI!) {
resource(url: $url) {
... on Issue {
projectItems(first: 10) {
nodes { id }
}
}
}
}' -f url="${{ github.event.issue.html_url }}" \
--jq '.data.resource.projectItems.nodes[0].id' 2>/dev/null || true)
echo "item_id=$ITEM_ID" >> "$GITHUB_OUTPUT"
- name: Set status to In Progress
if: steps.get-item.outputs.item_id != '' && steps.get-item.outputs.item_id != 'null'
env:
GH_TOKEN: ${{ secrets.PROJECT_TOKEN }}
run: |
gh api graphql -f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: { singleSelectOptionId: $optionId }
}) {
projectV2Item { id }
}
}' \
-f projectId="$PROJECT_ID" \
-f itemId="${{ steps.get-item.outputs.item_id }}" \
-f fieldId="$STATUS_FIELD_ID" \
-f optionId="$IN_PROGRESS_OPTION_ID"
echo "Issue moved to In Progress"
# When a PR is opened → set "In review"
pr-opened:
if: github.event_name == 'pull_request' && github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Get project item ID
id: get-item
env:
GH_TOKEN: ${{ secrets.PROJECT_TOKEN }}
run: |
ITEM_ID=$(gh api graphql -f query='
query($url: URI!) {
resource(url: $url) {
... on PullRequest {
projectItems(first: 10) {
nodes { id }
}
}
}
}' -f url="${{ github.event.pull_request.html_url }}" \
--jq '.data.resource.projectItems.nodes[0].id')
echo "item_id=$ITEM_ID" >> "$GITHUB_OUTPUT"
- name: Set status to In review
if: steps.get-item.outputs.item_id != '' && steps.get-item.outputs.item_id != 'null'
env:
GH_TOKEN: ${{ secrets.PROJECT_TOKEN }}
run: |
gh api graphql -f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: { singleSelectOptionId: $optionId }
}) {
projectV2Item { id }
}
}' \
-f projectId="$PROJECT_ID" \
-f itemId="${{ steps.get-item.outputs.item_id }}" \
-f fieldId="$STATUS_FIELD_ID" \
-f optionId="$IN_REVIEW_OPTION_ID"
# When a PR is merged → set PR + linked issues to "Done"
pr-merged:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Move PR to Done
env:
GH_TOKEN: ${{ secrets.PROJECT_TOKEN }}
run: |
# Get PR's project item ID
ITEM_ID=$(gh api graphql -f query='
query($url: URI!) {
resource(url: $url) {
... on PullRequest {
projectItems(first: 10) {
nodes { id }
}
}
}
}' -f url="${{ github.event.pull_request.html_url }}" \
--jq '.data.resource.projectItems.nodes[0].id')
if [ -n "$ITEM_ID" ] && [ "$ITEM_ID" != "null" ]; then
gh api graphql -f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: { singleSelectOptionId: $optionId }
}) {
projectV2Item { id }
}
}' \
-f projectId="$PROJECT_ID" \
-f itemId="$ITEM_ID" \
-f fieldId="$STATUS_FIELD_ID" \
-f optionId="$DONE_OPTION_ID"
echo "PR moved to Done"
fi
- name: Move closed issues to Done
env:
GH_TOKEN: ${{ secrets.PROJECT_TOKEN }}
run: |
# Extract "Closes #N" references from PR body
BODY='${{ github.event.pull_request.body }}'
NUMBERS=$(echo "$BODY" | grep -oiE '(closes|fixes|resolves)\s+#[0-9]+' | grep -oE '[0-9]+' || true)
for NUM in $NUMBERS; do
ISSUE_URL="https://github.com/${{ github.repository }}/issues/$NUM"
ITEM_ID=$(gh api graphql -f query='
query($url: URI!) {
resource(url: $url) {
... on Issue {
projectItems(first: 10) {
nodes { id }
}
}
}
}' -f url="$ISSUE_URL" \
--jq '.data.resource.projectItems.nodes[0].id' 2>/dev/null || true)
if [ -n "$ITEM_ID" ] && [ "$ITEM_ID" != "null" ]; then
gh api graphql -f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: { singleSelectOptionId: $optionId }
}) {
projectV2Item { id }
}
}' \
-f projectId="$PROJECT_ID" \
-f itemId="$ITEM_ID" \
-f fieldId="$STATUS_FIELD_ID" \
-f optionId="$DONE_OPTION_ID"
echo "Issue #$NUM moved to Done"
fi
done
# When an issue is closed directly → set to "Done"
issue-closed:
if: github.event_name == 'issues' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Move issue to Done
env:
GH_TOKEN: ${{ secrets.PROJECT_TOKEN }}
run: |
ITEM_ID=$(gh api graphql -f query='
query($url: URI!) {
resource(url: $url) {
... on Issue {
projectItems(first: 10) {
nodes { id }
}
}
}
}' -f url="${{ github.event.issue.html_url }}" \
--jq '.data.resource.projectItems.nodes[0].id')
if [ -n "$ITEM_ID" ] && [ "$ITEM_ID" != "null" ]; then
gh api graphql -f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: { singleSelectOptionId: $optionId }
}) {
projectV2Item { id }
}
}' \
-f projectId="$PROJECT_ID" \
-f itemId="$ITEM_ID" \
-f fieldId="$STATUS_FIELD_ID" \
-f optionId="$DONE_OPTION_ID"
echo "Issue moved to Done"
fi