Last active
May 24, 2020 06:23
-
-
Save Nilanshrajput/202c9fc6b8e251ea4699e7e6b9b2144a to your computer and use it in GitHub Desktop.
Set labels across all the repositories in organisation, get list of repos under an org, delete previous labels, set new labels
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 | |
from requests.auth import HTTPBasicAuth | |
import json | |
def get_repos(org="OpenMined"): | |
r=requests.get(f'https://api.github.com/orgs/{org}/repos') | |
json_data = r.json() | |
repo_names = [entity["name"] for entity in json_data] | |
return repo_names | |
def delete_default_labels(repo_names): | |
[requests.delete(f'https://api.github.com/repos/OpenMined/{name}/labels', auth = HTTPBasicAuth('user','pass')) for name in repo_names] | |
def get_labels(repo_name): | |
r=requests.get(f'https://api.github.com/repos/OpenMined/{repo_name}/labels') | |
json_data = r.json() | |
labels = [{"name":label["name"],"color":label['color'], #"default":label['default'], | |
"description":label['description']} for label in json_data] | |
return labels | |
def set_labels(repo_name, labels): | |
result = [requests.post(f'https://api.github.com/repos/OpenMined/{repo_name}/labels', data= json.dumps(label),auth = HTTPBasicAuth('user','pass')) for label in labels] | |
repo_names = get_repos(org="OpenMined") | |
# delete previous labels | |
delete_default_labels(repo_names) | |
# get the labels you want tp put in all repos | |
# labels is a list of label of format -'{"name":"In Analysis","color":"fbca04","description":"cool label"}' | |
labels = get_labels("PySyft") | |
# '{"name":"In Analysis","color":"fbca04"}' | |
# go through each repo and set labels | |
for repo in repo_names: | |
set_labels(repo, labels) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment