Created
November 14, 2024 01:04
-
-
Save Consolatis/fbd08387951c07f8c3bc86449333f045 to your computer and use it in GitHub Desktop.
GitHub graphql example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ENDPOINT="https://api.github.com/graphql" | |
orga=$some_orga | |
repo=$some_repo | |
ro_token="$GH_READ_ONLY_TOKEN" | |
parser=$(command -v jq) | |
test -z "$parser" && parser=cat | |
send_request() { | |
query='{ "query": "query { '"$1"' } "}' | |
#echo "Sending $query" >&2 | |
curl --silent -H "Authorization: bearer $ro_token" --request POST --data "$query" "$ENDPOINT" | |
} | |
introspect() { | |
send_request '__type(name: \"'"$1"'\") { name, kind, description, fields { name } }' | |
} | |
check() { | |
send_request "viewer { login }" | |
} | |
request_discussion() { | |
if test $# -ne 3; then | |
printf "\x1b[31mInvalid arguments for \x1b[0;1m%s()\x1b[m\n" request_discussion >&2 | |
return | |
fi | |
_orga=$1 | |
_repo=$2 | |
_id=$3 | |
send_request 'repository(owner: \"'"$_orga"'\", name: \"'"$_repo"'\") { discussion(number: '"$_id"') { category { name }, title, body, closed, url } }' | |
} | |
request_issue() { | |
if test $# -ne 3; then | |
printf "\x1b[31mInvalid arguments for \x1b[0;1m%s()\x1b[m\n" request_issue >&2 | |
return | |
fi | |
_orga=$1 | |
_repo=$2 | |
_id=$3 | |
send_request 'repository(owner: \"'"$_orga"'\", name: \"'"$_repo"'\") { issue(number: '"$_id"') { title, body, closed, url } }' | |
} | |
request_pr() { | |
if test $# -ne 3; then | |
printf "\x1b[31mInvalid arguments for \x1b[0;1m%s()\x1b[m\n" request_pr >&2 | |
return | |
fi | |
_orga=$1 | |
_repo=$2 | |
_id=$3 | |
send_request 'repository(owner: \"'"$_orga"'\", name: \"'"$_repo"'\") { pullRequest(number: '"$_id"') { title, body, closed, merged, url } }' | |
} | |
examples() { | |
check | |
#request_issue $orga $repo 2313 | |
#request_pr $orga $repo 2310 | |
#request_discussion $orga $repo 2309 | |
#introspect Issue | |
#introspect PullRequest | |
#introspect Discussion | |
} | |
examples | $parser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment