-
Notifications
You must be signed in to change notification settings - Fork 0
233 lines (208 loc) · 8.98 KB
/
update-deployment-issue.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
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
name: Update Deployment Issue
on:
workflow_dispatch:
inputs:
organization:
required: true
default: "CoveredCA"
description: Name of the organization the project is in
project-number:
required: true
default: 5
description: The number of the project from the project web url
application-name:
required: true
default: "cca-salesforce-sapi"
description: The name of the application the deployment issue was created for
environment:
required: true
default: "dev"
description: The enmviropnment the deployment issue is calling for
version:
required: true
default: "1.0.10"
description: The version of the application to be deployed to the environment
debug:
required: false
default: false
description: more verbose output for debugging purposes
jobs:
updateIssue:
name: Update Project Issue
runs-on: ubuntu-latest
steps:
- name: Get token from Github App
id: app-token
uses: CoveredCA/common-devops/packages/app-token@main
with:
client-id: ${{ secrets.MULESOFT_GITHUBAPP_CLIENTID}}
privatekey: ${{ secrets.MULESOFT_GITHUBAPP_PRIVATEKEY }}
- name: Collect ID's for Deployment Issue Update
shell: bash
env:
GITHUB_TOKEN: ${{ env.github_automationbot_token }}
GH_TOKEN: ${{ env.github_automationbot_token }}
run: |
echo "*********************************************"
echo "GitHub Graph API Grab ID's For Graph Queries "
echo "*********************************************"
echo " ****************"
echo " * Get Issue ID *"
echo " ****************"
# Initial cursor is empty
CURSOR=""
# Loop until all pages are fetched
while : ; do
# Execute GraphQL query
RESPONSE=$(gh api graphql -f query='
query($org: String!, $number: Int!, $cursor: String) {
organization(login: $org) {
projectV2(number: $number) {
items(first: 100, after: $cursor) {
pageInfo {
hasNextPage
endCursor
}
nodes {
id
content {
... on Issue {
id
number
title
}
}
}
}
}
}
}' -f org="${{ inputs.organization }}" -F number="${{ inputs.project-number }}" -f cursor="$CURSOR")
# Parse items and do something with them, e.g., append to a file
echo "$RESPONSE" | jq '.data.organization.projectV2.items.nodes[]' >> deployment_issues.json
# Check if there's a next page; if not, break the loop
HAS_NEXT_PAGE=$(echo "$RESPONSE" | jq '.data.organization.projectV2.items.pageInfo.hasNextPage')
if [ "$HAS_NEXT_PAGE" != "true" ]; then
break
fi
# Update cursor to fetch next page
CURSOR=$(echo "$RESPONSE" | jq -r '.data.organization.projectV2.items.pageInfo.endCursor')
done
echo "All items fetched successfully."
echo "Parsing output data file"
ISSUE_ID=$(jq -r '. | select(.content.title | test("Deployment")) | select(.content.title | test("${{ inputs.environment }}")) | select(.content.title | test("${{ inputs.application-name }}")) | select(.content.title | test("${{ inputs.version }}")) | .id' deployment_issues.json)
echo " ******************"
echo " * Get Project ID *"
echo " ******************"
PROJECT_ID=$(gh api graphql -f query='{
organization(login: $org) {
login
projectsV2(first: 100) {
edges {
node {
id
title
}
}
}
}
}' -f org="${{ inputs.organization }}" | jq -r '.data.organization.projectsV2.edges[] | select(.node.title | test("Deployment")) | .node.id')
echo " ******************"
echo " * Get Field ID's *"
echo " ******************"
FIELD_DATA=$(gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org="${{ inputs.organization }}" -F number="5" | jq '.data.organization.projectV2.fields.nodes[] | select((.name | test("Environment")) or (.name | test("Version")))')
FIELD_ID_ENVIRONMENT=$(echo "$FIELD_DATA" | jq -r '. | select(.name | test("Environment")) | .id')
FIELD_ID_VERSION=$(echo "$FIELD_DATA" | jq -r '. | select(.name | test("Version")) | .id')
echo " *************************************"
echo " * Get Environment Field Option ID's *"
echo " *************************************"
FIELD_ENVIRONMENT_OPTION_ID=$(gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org="${{ inputs.organization }}" -F number="${{ inputs.project-number }}" | jq '.data.organization.projectV2.fields.nodes[] | select(.name | test("Environment")) | .options[]' | jq -r '. | select(.name | test("${{ inputs.environment }}")) | .id')
echo "*******************************************************"
echo "GitHub Graph API Update Custom Fields on Project Items "
echo "*******************************************************"
echo "Updating Environment Field"
echo ""
gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: "$PROJECT_ID"
itemId: "$ISSUE_ID"
fieldId: "$FIELD_ID_ENVIRONMENT"
value: {
singleSelectOptionId: "$FIELD_ENVIRONMENT_OPTION_ID"
}
}
)
{
projectV2Item {
id
}
}
}'
echo ""
echo "Updating Version Field"
echo ""
gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: "$PROJECT_ID"
itemId: "$ISSUE_ID"
fieldId: "$FIELD_ID_VERSION"
value: {
text: "${{ inputs.version }}"
}
}
)
{
projectV2Item {
id
}
}
}'