-
Notifications
You must be signed in to change notification settings - Fork 3
/
github_graphql.sh
49 lines (43 loc) · 961 Bytes
/
github_graphql.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
#!/usr/bin/env bash
ghgql_most_recent_branches_query() {
local org="$1"
local repo="$2"
local refs_query="$3"
echo "
query {
repository(owner: \"$org\", name: \"$repo\") {
refs(
refPrefix: \"refs/heads/\",
first: 32,
query: \"$refs_query\",
orderBy: { field: TAG_COMMIT_DATE, direction: DESC }
) {
edges {
node {
name
}
}
}
}
}
"
}
ghgql_post() {
local github_graphql_api="$1"
local github_api_token="$2"
local query="$3"
local req_body
req_body="{ \"query\": \"$(echo "$query" | tr -d '\n' | sed 's/"/\\"/g')\" }"
>&2 echo "
Sending GraphQL body to $github_graphql_api
Raw query: $query
Request body: $req_body
"
curl \
-sSL \
-H "Content-Type: application/json" \
-H "Authorization: bearer $github_api_token" \
-X POST \
-d "$req_body" \
"$github_graphql_api"
}