Skip to content

Instantly share code, notes, and snippets.

@meatballhat
Created July 22, 2016 17:38
Show Gist options
  • Save meatballhat/7f596ff4df0c047ccbfd76df3a9bf463 to your computer and use it in GitHub Desktop.
Save meatballhat/7f596ff4df0c047ccbfd76df3a9bf463 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -o errexit
set -o xtrace
: ${GITHUB_TOKEN:=fababababdadab0000}
BRANCH_NAME="bot-test-$(date -u +%s)"
curl -sf -H "Authorization: token ${GITHUB_TOKEN}" \
https://api.github.com/repos/travis-infrastructure/packer-build/git/refs/heads/master > out.json
MASTER_COMMIT=$(jq -r .object.sha < out.json)
curl -sf -H "Authorization: token ${GITHUB_TOKEN}" \
https://api.github.com/repos/travis-infrastructure/packer-build/git/commits/${MASTER_COMMIT} > out.json
MASTER_TREE=$(jq -r .tree.sha < out.json)
curl -sf -X POST -H "Authorization: token ${GITHUB_TOKEN}" -d '
{
"content": "who woulda thunk it\n"
}' https://api.github.com/repos/travis-infrastructure/packer-build/git/blobs > out.json
BLOB_SHA=$(jq -r .sha < out.json)
curl -sf -X POST -H "Authorization: token ${GITHUB_TOKEN}" -d '
{
"base_tree": "'${MASTER_TREE}'",
"tree": [
{
"type": "blob",
"path": "testing.txt",
"mode": "100644",
"sha": "'${BLOB_SHA}'"
}
]
}' https://api.github.com/repos/travis-infrastructure/packer-build/git/trees > out.json
BLOB_TREE=$(jq -r .sha < out.json)
curl -sf -X POST -H "Authorization: token ${GITHUB_TOKEN}" -d '
{
"tree": "'${BLOB_TREE}'",
"parents": [
"'${MASTER_COMMIT}'"
],
"message": "ohai just testing",
"author": {
"name": "Dan Bot",
"email": "[email protected]"
}
}' https://api.github.com/repos/travis-infrastructure/packer-build/git/commits > out.json
BLOB_COMMIT=$(jq -r .sha < out.json)
curl -sf -X POST -H "Authorization: token ${GITHUB_TOKEN}" -d '
{
"ref": "refs/heads/'${BRANCH_NAME}'",
"sha": "'${BLOB_COMMIT}'"
}' https://api.github.com/repos/travis-infrastructure/packer-build/git/refs > out.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment