Last active
May 9, 2020 01:33
-
-
Save kuceb/3ebffb89350b76771b03a3952dbbbc39 to your computer and use it in GitHub Desktop.
This file contains 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 | |
branchname=${1:-$(git rev-parse --abbrev-ref HEAD)} | |
if ! [ -x "$(command -v jq)" ]; then | |
echo 'Error: "jq" is not installed.' >&2 | |
exit 1 | |
fi | |
if [ ! $SECRET_GH_TOKEN ]; then | |
printf 'Error: [36m$SECRET_GH_TOKEN[00m is not set. \n - set $SECRET_GH_TOKEN to the token from: \n [33mhttps://github.com/settings/tokens/new?scopes=repo&description=gh-cli-status-checks[00m \n (e.g. append to ~/.bashrc: [32mexport SECRET_GH_TOKEN=token[00m) ' >&2 | |
exit 1 | |
fi | |
result=$( | |
curl --request POST \ | |
--url https://api.github.com/graphql \ | |
--header 'authorization: Bearer '$SECRET_GH_TOKEN'' \ | |
--header 'content-type: application/json' \ | |
-s \ | |
--data '{"query":"query ($foo: String) {\n viewer {\n login\n pullRequests(orderBy: {field: UPDATED_AT, direction: ASC}, last: 1, headRefName: $foo) {\n edges {\n node {\n id\n title\n state\n commits(last: 1) {\n edges {\n node {\n id\n commit {\n status {\n contexts {\n id\n state\n targetUrl\n description\n context\n }\n }\n message\n committedDate\n author {\n name\n }\n }\n }\n }\n }\n baseRefName\n headRefName\n permalink\n }\n }\n }\n }\n}\n","variables":{"foo":"'$branchname'"}}' | |
) | |
foundPR=$( | |
echo $result | jq -r \ | |
'.data.viewer.pullRequests.edges[]' 2>/dev/null | |
) | |
if [[ -z $foundPR ]]; then | |
echo "no PRs found with branch name [31m[01m$branchname[00m from [36m$(echo $result | jq -r '.data.viewer.login')[00m" | |
exit 1 | |
fi | |
echo $result | jq -r \ | |
'.data.viewer.pullRequests.edges | .[0] | |
| "PR" + "([01m" + if .node.state == "MERGED" then "[35m" elif .node.state=="CLOSED" then "[31m" else "[32m" end +.node.state + "[00m): " +"[01m"+.node.title+"[00m" , | |
"[02m——— " + .node.permalink + " ———[00m", | |
( | |
.node.commits.edges[] | "[02m" + .node.commit.author.name + " - " + (.node.commit.committedDate | fromdateiso8601 | strftime("%a %x %r")) + "\n " + (.node.commit.message | (.[0:79] | rtrimstr(" ")) + (if length > 79 then "..." else "" end) ) + "[00m", | |
( | |
.node.commit.status.contexts | map({title:.context, state:.state}) | |
| | |
( | |
map(select(.state != "SUCCESS")) | |
| [ (map(select(.state == "FAILURE")) | map({title:.title, state: "[31m✘[00m"})), (map(select(.state == "PENDING")) | map({title:.title, state: "[33m⬤[00m"})) ] | flatten | |
| .[] | .state + " " + .title | |
), | |
( | |
"[32m✓ " | |
+ (map(select(.state == "SUCCESS"))| length | tostring) | |
+ " passed" | |
) | |
) | |
) | |
' | |
## print jq to columns | |
# | [.[]| with_entries( .key |= ascii_downcase ) ] | |
# | (.[0] |keys_unsorted | @tsv), (.[]|.|map(.) |@tsv) | |
# | column -t -s $'\t' |
can we add this as a script to the cypress
repo?
I guess hypothetically this could just be a regular node
script not bash... but i get it - you want something that works everywhere right.
could be nice to make a legit @cypress
module and publish to npm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
invoke this script from a git repo with:
branch name
from which to lookup PRthink it still needs time localization