/
gh_api_lib_user.sh
70 lines (63 loc) · 2.82 KB
/
gh_api_lib_user.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
#!/bin/bash
TMP_STORE_LOCATION=/tmp/api_response.json
# getUserProject queries the github api for the specific project
# 1: username
# 2: project id (number)
function getUserProject() {
local USER=$1
local PROJECT_NUMBER=$2
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
query($user: String!, $number: Int!) {
user(login: $user){
projectNext(number: $number) {
id
fields(first:20) {
nodes {
id
name
settings
}
}
}
}
}' -f user=$USER -F number=$PROJECT_NUMBER > $TMP_STORE_LOCATION
}
# extractUserProjectID returns the project id
function extractUserProjectID() {
jq '.data.user.projectNext.id' $TMP_STORE_LOCATION | sed -e "s+\"++g"
}
# extractUserFieldID returns the field id
# 1: field name
function extractUserFieldID() {
local fieldName=$(echo $1 | sed -e "s+\"++g") # remove quotes
jq -r ".data.user.projectNext.fields.nodes[] | select(.name == \"$fieldName\").id" $TMP_STORE_LOCATION
}
# extractUserFieldNodeIterationSettingValue returns the field node setting value id
# 1: field name
# 2: select value
#
# NOTE: If the value is @current or @next, we check the the array of iterations and return the current or next iteration id.
function extractUserFieldNodeIterationSettingValue() {
local field_name=$(echo $1 | sed -e "s+\"++g") # remove quotes
select_value=$(echo $2 | sed -e "s+\"++g") # remove quotes
iterations_for_field=$(jq ".data.user.projectNext.fields.nodes[] | select(.name==\"$field_name\").settings | fromjson.configuration.iterations[]" $TMP_STORE_LOCATION)
dates=$(echo $iterations_for_field | jq -r ".start_date" | sort )
STRINGTEST=(${dates[@]})
if [ "$select_value" == "@current" ]; then
iteration_selected=${STRINGTEST[0]}
echo -e $iterations_for_field | jq "select(.start_date==\"$iteration_selected\") |.id" | sed -e "s+\"++g"
elif [ "$select_value" == "@next" ]; then
iteration_selected=${STRINGTEST[1]}
echo -e $iterations_for_field | jq "select(.start_date==\"$iteration_selected\") |.id" | sed -e "s+\"++g"
else
echo -e $iterations_for_field | jq "select(.title==\"$select_value\") |.id" | sed -e "s+\"++g"
fi
}
# extractUserFieldNodeSelectSettingValue returns the field node setting value id
# 1: field name
# 2: select value
function extractUserFieldNodeSelectSettingValue() {
local fieldName=$(echo $1 | sed -e "s+\"++g") # remove quotes
selectValue=$(echo $2 | sed -e "s+\"++g") # remove quotes
jq ".data.user.projectNext.fields.nodes[] | select(.name == \"$fieldName\").settings | fromjson.options[] | select(.name==\"$selectValue\") |.id" $TMP_STORE_LOCATION | sed -e "s+\"++g"
}