Last active
February 21, 2024 17:00
-
-
Save crsantos/8c585ebb89201e9f4e170b5ce3461017 to your computer and use it in GitHub Desktop.
Simply deletes all labels on all repos from an Organization and create new ones
This file contains hidden or 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
from github import Github # https://github.com/PyGithub/PyGithub | |
import time | |
new_labels_to_add = [ | |
("low", "78d60c"), | |
("medium", "f4df42"), | |
("high", "d12349") | |
] | |
g = Github("ADD_YOUR_ACCESS_TOKEN_HERE") | |
# Just pick the first org (need more? adapt!) | |
org = g.get_user().get_orgs()[0] | |
print("Fetching " + org.name) | |
for repo in org.get_repos(): | |
if repo.permissions.push is False: | |
print("Ignoring not-allowed repo: %s (permissions.push= %s)" % (repo.name, str(repo.permissions.push))) | |
continue | |
print("For %s" % repo.name) | |
for label in repo.get_labels(): | |
if label.url: | |
print("Deleting: "+ label.url) | |
label.delete() | |
else: | |
print("cannot delete: "+ label.name) | |
time.sleep(0.5) | |
for newlabel in new_labels_to_add: | |
print("creating: %s" % str(newlabel)) | |
repo.create_label(newlabel[0], newlabel[1]) | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment