Skip to content

Instantly share code, notes, and snippets.

@dzimine
Created December 5, 2016 03:04
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 dzimine/198221772d56e4f846740eccb9d53ce1 to your computer and use it in GitHub Desktop.
Save dzimine/198221772d56e4f846740eccb9d53ce1 to your computer and use it in GitHub Desktop.
Add alias to StackStorm-exchange repos so that they continue to work with pre 2.1 versions
#!/usr/bin/env python
import json
import requests
API_EP = "https://api.github.com"
REPO = "/repos/Stackstorm-exchange/"
TOKEN = "&access_token=ADD_VALID_TOKEN_HERE"
def get_repo_list():
r = requests.get("https://api.github.com/orgs/StackStorm-exchange/repos?per_page=20")
if not r.ok:
print "Error getting list of repos: {0}\n{1}".format(r.status_code, r.content[:100])
exit(1)
# r = open('./repo-list.json').read()
data = json.loads(r.content)
return [d['name'] for d in data if d['name'].startswith('stackstorm-')]
def add_alias(name, alias):
print ("Trying alias [{0}]...".format(alias)),
if requests.get(API_EP + REPO + alias + '?' + TOKEN).ok:
print "EXISTS!"
return
print "Missing, setting up."
url = API_EP + REPO + name + '?' + TOKEN
r1 = requests.patch(url, json={'name': alias})
if r1.ok:
print "\tAlias set up to {0}".format(alias)
else:
print "\nError setting alias: {0}\n{1}".format(r1.status_code, r1.content[:100])
r2 = requests.patch(url, json={'name': name})
if r2.ok:
print "\tName set up to {0}".format(name)
else:
print "\nError setting name: {0}\n{1}".format(r1.status_code, r1.content[:100])
if __name__ == '__main__':
names = get_repo_list()
print "Setting aliases to {0} repos".format(len(names))
for name in names:
alias = name.split("-")[1]
add_alias(name, alias)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment