23
23
pull_request_review :
24
24
# Run this action when a PR is reviewed
25
25
types : [submitted]
26
-
26
+
27
27
env :
28
- ORG : ${{ github.event.repository.owner.login }}
29
- PR_NUMBER : ${{ github.event.pull_request.number }}
30
- REPO : ${{ github.event.repository.name }}
31
- PR_GLOBAL_ID : ${{ github.event.pull_request.node_id}}
28
+ ORG : ${{ github.event.repository.owner.login }}
29
+ PR_NUMBER : ${{ github.event.pull_request.number }}
30
+ REPO : ${{ github.event.repository.name }}
31
+ PR_GLOBAL_ID : ${{ github.event.pull_request.node_id}}
32
32
33
- # The environment vars below are hard-coded from external queries to save time + complexity here
34
- # Note: PVT means Project V2, not "Private"
35
- # PVT = Project V2, PVTSSF = Project V2 Single Select Field, PVTIF = Project V2 Iteration Field
36
- PROJECT_ID : " PVT_kwDOBkAsks4ACeio"
37
- STATUS_FIELD_ID : " PVTSSF_lADOBkAsks4ACeiozgBbno0"
38
- WORKING_SPRINT_FIELD_ID : " PVTIF_lADOBkAsks4ACeiozgJ_KCY"
39
- START_SPRINT_FIELD_ID : " PVTIF_lADOBkAsks4ACeiozgI90p0"
40
- IN_PROGRESS_PROJECT_OPTION_ID : " 47fc9ee4"
41
- IN_REVIEW_PROJECT_OPTION_ID : " eb7a6302"
33
+ # The environment vars below are hard-coded from external queries to save time + complexity here
34
+ # Note: PVT means Project V2, not "Private"
35
+ # PVT = Project V2, PVTSSF = Project V2 Single Select Field, PVTIF = Project V2 Iteration Field
36
+ PROJECT_ID : " PVT_kwDOBkAsks4ACeio"
37
+ STATUS_FIELD_ID : " PVTSSF_lADOBkAsks4ACeiozgBbno0"
38
+ WORKING_SPRINT_FIELD_ID : " PVTIF_lADOBkAsks4ACeiozgJ_KCY"
39
+ START_SPRINT_FIELD_ID : " PVTIF_lADOBkAsks4ACeiozgI90p0"
40
+ IN_PROGRESS_PROJECT_OPTION_ID : " 47fc9ee4"
41
+ IN_REVIEW_PROJECT_OPTION_ID : " eb7a6302"
42
42
43
43
jobs :
44
44
project_automation_in_progress :
45
45
runs-on : ubuntu-latest
46
46
47
47
# We use the default GitHub token to perform the draft update because
48
- # The pull_request_review trigger does not grant access to the secrets.PROJECT_MANAGEMENT_PAT
48
+ # The pull_request_review trigger does not grant access to secrets
49
49
permissions :
50
50
issues : write
51
51
pull-requests : write
52
-
52
+
53
53
steps :
54
54
- name : Check if changes requested from a reviewer
55
55
id : check_changes_requested
58
58
if [ ${{ github.event.review.state }} != 'changes_requested' ]; then
59
59
echo "Changes not requested, exiting"
60
60
exit 0
61
-
61
+
62
62
# If it is requesting changes, set PR to draft
63
63
# We use the default token here since we're granting write access to the PR
64
64
elif [ ${{ github.event.pull_request.draft }} == false ]; then
80
80
- name : Select Status Field Value
81
81
id : select_status_field_value
82
82
if : github.event_name == 'pull_request_target'
83
- env :
84
- GITHUB_TOKEN : ${{ secrets.PROJECT_MANAGEMENT_PAT }}
85
83
run : |
86
84
# If it's not a draft and it's an opened trigger, the status should be "Ready for Review", otherwise "In Progress"
87
85
if [ ${{ github.event.pull_request.draft }} == false ] && [ ${{ github.event.action }} == "opened" ]; then
96
94
- name : Get PR Project ID
97
95
id : get_pr_id
98
96
if : github.event_name == 'pull_request_target'
99
- env :
100
- GITHUB_TOKEN : ${{ secrets.PROJECT_MANAGEMENT_PAT }}
101
97
run : |
102
98
# Query up to 10 projects for the PR
103
99
gh api graphql -f query='
@@ -122,20 +118,18 @@ jobs:
122
118
}
123
119
}
124
120
}' > project_data.json
125
-
121
+
126
122
# Filter the json result to only the project-specific ID for the PR
127
123
# A PR can be in multiple projects so we need to filter by the project ID we want
128
124
pr_id=$(jq -r '.data.organization.repository.issueOrPullRequest.projectItems.edges[] |
129
125
select(.node.project.id == "${{ env.PROJECT_ID }}") |
130
126
.node.id' project_data.json)
131
127
echo "PR_ID=$pr_id" >> $GITHUB_ENV
132
128
continue-on-error : true
133
-
129
+
134
130
- name : Set PR Fields
135
131
id : set_pr_fields
136
132
if : github.event_name == 'pull_request_target'
137
- env :
138
- GITHUB_TOKEN : ${{ secrets.PROJECT_MANAGEMENT_PAT }}
139
133
run : |
140
134
gh api graphql -f query='
141
135
mutation {
@@ -154,7 +148,7 @@ jobs:
154
148
}
155
149
}
156
150
}'
157
-
151
+
158
152
# Check if the PR has a start sprint assigned, save the result for the linked issues
159
153
gh api graphql -f query='
160
154
query {
@@ -171,7 +165,7 @@ jobs:
171
165
}' > start_sprint_exists_data.json
172
166
start_sprint_option_id=$(jq -r '.data.node.fieldValueByName.id' start_sprint_exists_data.json)
173
167
echo "START_SPRINT_OPTION_ID=$start_sprint_option_id" >> $GITHUB_ENV
174
-
168
+
175
169
# If there is no start sprint assigned, assign the current start sprint
176
170
if [ "$start_sprint_option_id" == 'null' ]; then
177
171
# Get current start sprint iteration id
@@ -197,7 +191,7 @@ jobs:
197
191
}' > start_sprint_option_data.json
198
192
current_start_sprint_option_id=$(jq -r '.data.node.field.configuration.iterations[0].id' start_sprint_option_data.json)
199
193
echo "CURRENT_START_SPRINT_OPTION_ID=$current_start_sprint_option_id" >> $GITHUB_ENV
200
-
194
+
201
195
# The query below is constructed differently than the ones above due to bash variable syntax + github actions syntax interactions
202
196
QUERY="mutation {
203
197
updateProjectV2ItemFieldValue(
@@ -217,7 +211,7 @@ jobs:
217
211
}"
218
212
gh api graphql --field query="$QUERY"
219
213
fi
220
-
214
+
221
215
# Assign the current working sprint to the PR (faster/simpler to just overwrite even if it is the same)
222
216
gh api graphql -f query='
223
217
query {
@@ -240,7 +234,7 @@ jobs:
240
234
}' > working_sprint_options_data.json
241
235
current_working_sprint_option_id=$(jq -r '.data.node.field.configuration.iterations[0].id' working_sprint_options_data.json)
242
236
echo "CURRENT_WORKING_SPRINT_OPTION_ID=$current_working_sprint_option_id" >> $GITHUB_ENV
243
-
237
+
244
238
# Set the working sprint to the current working sprint
245
239
QUERY="mutation {
246
240
updateProjectV2ItemFieldValue(
@@ -260,12 +254,10 @@ jobs:
260
254
}"
261
255
gh api graphql --field query="$QUERY"
262
256
continue-on-error : true
263
-
257
+
264
258
- name : Sync Linked Issues
265
259
id : sync_linked_issues
266
260
if : github.event_name == 'pull_request_target'
267
- env :
268
- GITHUB_TOKEN : ${{ secrets.PROJECT_MANAGEMENT_PAT }}
269
261
run : |
270
262
# Find the linked issues to the PR
271
263
gh api graphql -f query='
@@ -303,7 +295,7 @@ jobs:
303
295
issue_ids=$(jq -r '.data.organization.repository.issueOrPullRequest.closingIssuesReferences.edges[].node.projectItems.edges[] |
304
296
select(.node.project.id == "${{ env.PROJECT_ID }}") |
305
297
.node.id' linked_issues.json)
306
-
298
+
307
299
# For each linked issue, set the status to "In Progress", the Working Sprint to the current working sprint
308
300
# If there's no Start Sprint, set that to the current Start Sprint as well
309
301
for issue_id in $issue_ids; do
0 commit comments