Skip to content

Instantly share code, notes, and snippets.

@jb55
Created October 13, 2017 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jb55/1cb23577452f10f29190b7c616ae43ab to your computer and use it in GitHub Desktop.
Save jb55/1cb23577452f10f29190b7c616ae43ab to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
access_token=$GITHUB_ACCESS_TOKEN
api() {
curl -sL -H "Authorization: token $access_token" "$@"
}
usage() {
printf "usage: git-pr-event <owner>/<repo> <pr> <body> <approve|reject|comment>\n" >&2
exit 1
}
getevent() {
case "$1" in
"approve")
printf "APPROVE\n"
;;
"reject")
printf "REQUEST_CHANGES\n"
;;
"comment")
printf "COMMENT\n"
;;
*)
printf "invalid event '%s', choose approve, reject or comment\n" "$1" >&2
exit 1
;;
esac
}
project="$1"
pr="$2"
body="$3"
event="${4:-approve}"
if [ -z $project ] || [ -z $pr ] || [ -z $body ]; then
usage
fi
base_url='https://api.github.com/repos/'"$project"
event=$(getevent $event)
review_id=$(api -X POST -d'{"body":"'"$body"'"}' "$base_url/pulls/$pr/reviews" | jq -r .id)
api -X POST -d '{"body":"'"$body"'", "event":"'"$event"'"}' \
"$base_url/pulls/$pr/reviews/$review_id/events" | jq -r '._links.html.href'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment