Created
October 15, 2016 10:32
-
-
Save ijse/a178bf6061fd4499a92f525d66ef2c7f 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 | |
# 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