Created
August 30, 2016 09:37
-
-
Save bforchhammer/12e9dbedc57218a07a4353b722c7acc2 to your computer and use it in GitHub Desktop.
Github Labeler
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 github3 | |
try: | |
prompt = raw_input | |
except NameError: | |
prompt = input | |
def two_factor(): | |
code = '' | |
while not code: | |
# The user could accidentally press Enter before being ready, | |
# let's protect them from doing that. | |
code = prompt('Enter 2FA code: ') | |
return code | |
gh_username = '' # Enter your username here! | |
gh_password = '' # Enter your personal access token here (https://github.com/settings/tokens) | |
gh = github3.login(gh_username, password=gh_password, two_factor_callback=two_factor) | |
labels_new = { | |
"Approved": "159818", | |
"Needs Review": "207de5", | |
"Needs Work": "e11d21", | |
"WIP": "eb6420", | |
} | |
for repo in gh.repositories(): | |
if repo.owner.login != 'dubsmash': | |
continue | |
print repo | |
labels = repo.labels() | |
label_names = [l.name for l in labels] | |
labels_to_keep = [] | |
labels_to_delete = [] | |
labels_to_create = [] | |
for new in labels_new: | |
if new in label_names: | |
continue | |
labels_to_create.append((new, labels_new[new])) | |
for old in labels: | |
if old.name in labels_new.keys(): | |
labels_to_keep.append(old) | |
continue | |
labels_to_delete.append(old) | |
print "Labels: " | |
for l in labels_to_keep: | |
print "* ", l | |
for l in labels_to_delete: | |
print "- ", l | |
for l in labels_to_create: | |
print "+ ", l[0] | |
changed = len(labels_to_delete) != 0 or len(labels_to_create) != 0 | |
if changed: | |
p = prompt("Should labels be updated? [yes|no|quit] ") | |
if p.lower() in ['q', 'quit']: | |
print "Bye bye" | |
exit() | |
if p.lower() in ['y', 'yes']: | |
for name, color in labels_to_create: | |
created = repo.create_label(name, color) | |
print "Created", created | |
for old in labels_to_delete: | |
old.delete() | |
print "Deleted", old | |
else: | |
print "Skipped" | |
print "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment