-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathproject-update-linked-issues.yaml
More file actions
201 lines (182 loc) · 7.28 KB
/
project-update-linked-issues.yaml
File metadata and controls
201 lines (182 loc) · 7.28 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
name: Project - Update Linked Issues
# This workflow takes a PR and updates the linked issues to match the PR
# Issues do not have a connection back to the PRs, so this workflow can only be called by the PR
# It's flexible what fields you update
# This workflow will primarily be called by the 'get-set' workflows
on:
workflow_call:
inputs:
PROJECT_ID:
description: "The Project's graphQL node ID"
type: string
required: true
PR_PROJECT_ID:
description: "The PR's graphQL project-specific ID "
type: string
required: true
PR_NODE_ID:
description: "The PR's graphQL node ID"
default: null
type: string
UPDATE_FIELD_TYPE:
description: "The type of field to update - [text, number, date, single_select, iteration]"
type: string
required: true
UPDATE_FIELD_ID:
description: "The graphQL node ID of the iteration field"
type: string
required: true
UPDATE_FIELD_VALUE:
description: "The value to set the field to"
type: string
required: true
secrets:
ADD_TO_PROJECT_GITHUB_TOKEN:
description: "Project Access Token"
required: true
jobs:
synchronize_linked_issues:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Sync Linked Issues
id: sync_linked_issues
env:
GITHUB_TOKEN: ${{ secrets.ADD_TO_PROJECT_GITHUB_TOKEN }}
ENV_PR_NODE_ID: ${{ inputs.PR_NODE_ID }}
ENV_PROJECT_ID: ${{ inputs.PROJECT_ID }}
ENV_UPDATE_FIELD_TYPE: ${{ inputs.UPDATE_FIELD_TYPE }}
ENV_UPDATE_FIELD_ID: ${{ inputs.UPDATE_FIELD_ID }}
ENV_UPDATE_FIELD_VALUE: ${{ inputs.UPDATE_FIELD_VALUE }}
run: |
# Find the linked issues to the PR
# shellcheck disable=SC2016
gh api graphql -f prNodeId="$ENV_PR_NODE_ID" -f query='
query($prNodeId: ID!) {
node(id: $prNodeId) {
... on PullRequest {
closingIssuesReferences(first: 10) {
nodes {
projectItems(first: 10) {
nodes {
id
project {
id
}
}
}
}
}
}
}
}' > linked_issues.json
# Use jq with proper variable handling to get issue IDs
issue_ids=$(jq --arg project_id "$ENV_PROJECT_ID" -r '
.data.node.closingIssuesReferences.nodes[].projectItems.nodes[] |
select(.project.id == $project_id) |
.id' linked_issues.json)
# Exit if no issues found
if [ -z "$issue_ids" ]; then
echo "No linked issues found in project" >&2
exit 0
fi
# Process each issue
echo "$issue_ids" | while read -r issue_id; do
if [ -z "$issue_id" ]; then
continue
fi
case "$ENV_UPDATE_FIELD_TYPE" in
"iteration")
# shellcheck disable=SC2016
gh api graphql -f projectId="$ENV_PROJECT_ID" \
-f itemId="$issue_id" \
-f fieldId="$ENV_UPDATE_FIELD_ID" \
-f iterationId="$ENV_UPDATE_FIELD_VALUE" \
-f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $iterationId: String!) {
updateProjectV2ItemFieldValue(
input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: {iterationId: $iterationId}
}
) {
projectV2Item {id}
}
}'
;;
"single_select")
# shellcheck disable=SC2016
gh api graphql -f projectId="$ENV_PROJECT_ID" \
-f itemId="$issue_id" \
-f fieldId="$ENV_UPDATE_FIELD_ID" \
-f optionId="$ENV_UPDATE_FIELD_VALUE" \
-f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(
input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: {singleSelectOptionId: $optionId}
}
) {
projectV2Item {id}
}
}'
;;
"date"|"text")
# shellcheck disable=SC2016
gh api graphql -f projectId="$ENV_PROJECT_ID" \
-f itemId="$issue_id" \
-f fieldId="$ENV_UPDATE_FIELD_ID" \
-f value="$ENV_UPDATE_FIELD_VALUE" \
-f fieldType="$ENV_UPDATE_FIELD_TYPE" \
-f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $value: String!, $fieldType: String!) {
updateProjectV2ItemFieldValue(
input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: { text: $value }
}
) {
projectV2Item {id}
}
}'
;;
"number")
# shellcheck disable=SC2016
gh api graphql -f projectId="$ENV_PROJECT_ID" \
-f itemId="$issue_id" \
-f fieldId="$ENV_UPDATE_FIELD_ID" \
-f value="$ENV_UPDATE_FIELD_VALUE" \
-f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $value: Float!) {
updateProjectV2ItemFieldValue(
input: {
projectId: $projectId
itemId: $itemId
fieldId: $fieldId
value: { number: $value }
}
) {
projectV2Item {id}
}
}'
;;
*)
echo "Error: Invalid field type '$ENV_UPDATE_FIELD_TYPE'" >&2
exit 1
;;
esac
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "Error: Failed to update field for issue $issue_id" >&2
exit 1
fi
done
continue-on-error: true