Created
May 14, 2017 16:37
-
-
Save looneym/a448c9b3b62baaf918bd285103fe373c to your computer and use it in GitHub Desktop.
Create a branch in a remote repo using the Github API. Uses token auth.
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
import requests | |
import os | |
import json | |
TOKEN = os.environ['GH'] | |
NEW_BRANCH_NAME = '' | |
HASH = '' | |
AUTHOR= '' | |
REPO = '' | |
url = 'https://api.github.com/repos/{}/{}/git/refs'.format(AUTHOR, REPO) | |
payload = \ | |
{ | |
"ref": "refs/heads/{}".format(NEW_BRANCH_NAME), | |
"sha": "{}".format(HASH) | |
} | |
headers = \ | |
{ | |
'Content-Type': 'application/json', | |
'Authorization': 'token {}'.format(TOKEN) | |
} | |
r = requests.post(url=url, data=json.dumps(payload), headers=headers) | |
print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment