Skip to content

Instantly share code, notes, and snippets.

@noamtamim
Last active September 18, 2015 19:49
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 noamtamim/e45d16b0ca9cf7c046c6 to your computer and use it in GitHub Desktop.
Save noamtamim/e45d16b0ca9cf7c046c6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Simple GitHub push (https://developer.github.com/v3/repos/contents/#create-a-file)
# Mandatory arguments, as env vars:
# INPUT_FILE: local file to upload
# REPO_FULL_NAME: username/reponame
# REPO_PATH: full target path name (path/to/targetFile.txt)
# GH_TOKEN: an oauth2 access token (https://github.com/settings/tokens)
# Linux base64 inserts line breaks by default. Darwin doesn't.
case $(uname) in
Linux) BASE64="base64 --wrap=0"; ;;
Darwin) BASE64="base64"; ;;
*) echo Unknown system; exit 1; ;;
esac
DATA=$($BASE64 "$INPUT_FILE")
cat << EOF > gh_push_request.txt
{
"message": "Adding $REPO_PATH",
"content": "$DATA"
}
EOF
curl -X PUT "https://api.github.com/repos/$REPO_FULL_NAME/contents/$REPO_PATH?access_token=$GH_TOKEN" --data-binary @gh_push_request.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment