Last active
September 18, 2015 19:49
-
-
Save noamtamim/e45d16b0ca9cf7c046c6 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 | |
# 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