forked from leonsteinhaeuser/project-beta-automations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh_api_global.sh
235 lines (223 loc) · 6.81 KB
/
gh_api_global.sh
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
#!/bin/bash
# getItemID queries the github api for the specific item_id
# Required arguments:
# 1: project id
# 2: resource node id
function getItemID() {
local project_id=$1
local resource_id=$2
gh api graphql -f query='
mutation($project:ID!, $pr:ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $pr}) {
item {
id
}
}
}' -f project=$project_id -f pr=$resource_id --jq '.data.addProjectV2ItemById.item.id'
}
# extractFieldID returns the field uuid
# 1: field name (string)
function extractFieldID() {
local fieldName=$(echo $1 | sed -e "s+\"++g") # remove quotes
jq -r ".nodes[] | select(.name == \"$fieldName\").id" $TMP_STORE_LOCATION
}
# extractFieldNodeSingleSelectSettingValue returns the field node setting value id
# 1: field name (string)
# 2: select value (string)
function extractFieldNodeSingleSelectSettingValue() {
local fieldName=$(echo $1 | sed -e "s+\"++g") # remove quotes
local selectValue=$(echo $2 | sed -e "s+\"++g") # remove quotes
jq ".nodes[] | select(.name==\"$fieldName\").options[] | select(.name==\"$selectValue\").id" $TMP_STORE_LOCATION | sed -e "s+\"++g"
}
# extractFieldNodeIterationSettingValue returns the field node setting value id
# 1: field name (string)
# 2: select value (string)
#
# NOTE: If the value is @current or @next, we check the the array of iterations and return the current or next iteration id.
function extractFieldNodeIterationSettingValue() {
local field_name=$(echo $1 | sed -e "s+\"++g") # remove quotes
local select_value=$(echo $2 | sed -e "s+\"++g") # remove quotes
iterations_for_field=$(jq ".nodes[] | select(.name==\"$field_name\").configuration.iterations" $TMP_STORE_LOCATION)
dates=$(echo $iterations_for_field | jq -r '.[] | .startDate' | sort)
STRINGTEST=(${dates[@]})
if [ "$select_value" == "@current" ]; then
CURRENT_ITERATION=${STRINGTEST[0]}
echo -e $iterations_for_field | jq -r '.[] | select(.startDate == "'$CURRENT_ITERATION'").id'
elif [ "$select_value" == "@next" ]; then
NEXT_ITERATION=${STRINGTEST[1]}
echo -e $iterations_for_field | jq -r '.[] | select(.startDate == "'$NEXT_ITERATION'").id'
else
echo -e $iterations_for_field | jq -r ".[] | select(.title==\"$select_value\") | .id"
fi
}
# updateSingleSelectField updates the given item field with the defined value
# Required arguments:
# 1: project id
# 2: project item id
# 3: field id
# 4: field option string (id as string)
function updateSingleSelectField() {
local project_id=$1
local item_id=$2
local field_id=$3
local field_option=$4
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$fieldid: ID!
$fieldOption: String!
) {
updateProjectV2ItemFieldValue(
input: {
projectId: $project
itemId: $item
fieldId: $fieldid
value: {
singleSelectOptionId: $fieldOption
}
}
)
{
projectV2Item {
id
}
}
}' -f project=$project_id -f item=$item_id -f fieldid=$field_id -f fieldOption=$field_option | sed -e "s+\"++g"
}
# updateIterationField updates the given item field with the defined value
# Required arguments:
# 1: project id
# 2: project item id
# 3: field id
# 4: field option string (id as string)
function updateIterationField() {
local project_id=$1
local item_id=$2
local field_id=$3
local field_option=$4
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
mutation (
$project: ID!
$item: ID!
$fieldid: ID!
$fieldOption: String!
) {
set_status: updateProjectV2ItemFieldValue(
input: {
projectId: $project
itemId: $item
fieldId: $fieldid
value: {
iterationId: $fieldOption
}
}
)
{
projectV2Item {
id
}
}
}' -f project=$project_id -f item=$item_id -f fieldid=$field_id -f fieldOption=$field_option | sed -e "s+\"++g"
}
# updateTextField updates the given item field with the defined value
# Required arguments:
# 1: project id
# 2: project item id
# 3: field id
# 4: field value
function updateTextField() {
local PROJECT_ID=$1
local ITEM_ID=$2
local FIELD_ID=$3
local FIELD_VALUE=$4
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$fieldid: ID!
$fieldValue: String!
) {
updateProjectV2ItemFieldValue(
input: {
projectId: $project
itemId: $item
fieldId: $fieldid
value: {
text: $fieldValue
}
}
) {
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f fieldid=$FIELD_ID -f fieldValue="$FIELD_VALUE" | sed -e "s+\"++g"
}
# updateNumberField updates the given item field with the defined value
# Required arguments:
# 1: project id
# 2: project item id
# 3: field id
# 4: field value
function updateNumberField() {
local PROJECT_ID=$1
local ITEM_ID=$2
local FIELD_ID=$3
local FIELD_VALUE=$4
gh api graphql -f query="
mutation (
\$project: ID!
\$item: ID!
\$fieldid: ID!
) {
updateProjectV2ItemFieldValue(
input: {
projectId: \$project
itemId: \$item
fieldId: \$fieldid
value: {
number: $FIELD_VALUE
}
}
) {
projectV2Item {
id
}
}
}" -f project=$PROJECT_ID -f item=$ITEM_ID -f fieldid=$FIELD_ID | sed -e "s+\"++g"
}
# updateDateField updates the given item field with the defined value
# Required arguments:
# 1: project id
# 2: project item id
# 3: field id
# 4: field value
function updateDateField() {
local PROJECT_ID=$1
local ITEM_ID=$2
local FIELD_ID=$3
local FIELD_VALUE=$4
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$fieldid: ID!
$fieldValue: Date!
) {
updateProjectV2ItemFieldValue(
input: {
projectId: $project
itemId: $item
fieldId: $fieldid
value: {
date: $fieldValue
}
}
) {
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f fieldid=$FIELD_ID -f fieldValue="$FIELD_VALUE" | sed -e "s+\"++g"
}