Skip to content

Instantly share code, notes, and snippets.

@ijse
Created October 15, 2016 10:32
Show Gist options
  • Save ijse/a178bf6061fd4499a92f525d66ef2c7f to your computer and use it in GitHub Desktop.
Save ijse/a178bf6061fd4499a92f525d66ef2c7f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Request Github Api
#
# Usage:
# shells/request.sh <GET|POST> <api> [params]
#
# Sample:
# ./shells/request.sh POST merges \
# "{\"base\":\"master\",\"head\":\"develop\",\"commit_message\":\"$message\"}"
GithubApi="https://api.github.com"
# Read creditions from env GITHUB_AUTH = "<username>:<token>"
auth=${GITHUB_AUTH}
repo=${GITHUB_REPO}
method=${1:="GET"}
api=$2
params=$3
case $api in
(http*) : path=$api;;
*) path="${GithubApi}/repos/${repo}/${api}" ;;
esac
case "$method" in
POST | PUT | PATCH) has_stdin=1;;
esac
curl -nsSi \
-u $auth \
${has_stdin:+-d ${params}} \
-X "${method}" \
"${path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment