Skip to content

Instantly share code, notes, and snippets.

@Bockit
Last active December 18, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Bockit/5794123 to your computer and use it in GitHub Desktop.
Save Bockit/5794123 to your computer and use it in GitHub Desktop.
Simple script to sync labels to any repository. Usage: python synclabels.py owner/repo
import argparse
from getpass import getuser, getpass
from github3 import GitHub
user = raw_input('GitHub username: ')
password = ''
while not password:
password = getpass('Password for %s: ' % user)
print 'Signing in...'
g = GitHub(user, password)
print 'Signed in.'
parser = argparse.ArgumentParser()
parser.add_argument('repo', help='The repo you want to sync labels for. In the format owner/repo')
repo = parser.parse_args().repo
owner = repo.split('/')[0]
repo = repo.split('/')[1]
print 'Getting repository.'
repo = g.repository(owner, repo)
labels = {
'invalid': '#ffffff',
'unassigned': '#ffffff',
'data': '#ffffff',
'feature': '#ffffff',
'bug': '#ffffff',
'must': '#ffffff',
'should': '#ffffff',
'could': '#ffffff',
'wont': '#ffffff',
'urgent': '#ff0000',
}
labels = [{'name': k, 'color': labels[k]} for k in labels.keys()]
print 'Deleting labels'
for label in repo.iter_labels():
print 'Deleting %s' % label
label.delete()
print 'Creating labels'
for label in labels:
print 'Creating %s' % label
repo.create_label(**label)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment