Skip to content

Instantly share code, notes, and snippets.

@David-Estevez
Created December 6, 2017 16:31
Show Gist options
  • Save David-Estevez/c2d335d3370273be1628c8f98d2b76fb to your computer and use it in GitHub Desktop.
Save David-Estevez/c2d335d3370273be1628c8f98d2b76fb to your computer and use it in GitHub Desktop.
Customize automatically the labels of a new repo
"""
Update the labels in a repo
Requirements:
$ pip install begins requests
# Usage:
$ python labels.py --owner <repo_owner> --repo <repo_name> --api-key <GitHub API key>
"""
import json
import begin
import requests
@begin.start(auto_convert=True)
def main(owner='', repo='', api_key=''):
labels_to_delete = ['duplicate', 'enhancement', 'good first issue', 'help wanted', 'invalid', 'question', 'wontfix']
new_labels = [ ('ayúdanos!!', '33aa3f'),
('documentar', 'c2ffc6'),
('duda', 'cc317c'),
('duplicada', 'cccccc'),
('hardware', '80b20c'),
('idea', 'ec05f4'),
('inválida', 'e6e6e6'),
('para novatos', '7057ff'),
('prioridad:alta', 'fbca04'),
('prioridad:baja', '12baa6'),
('prioridad:crítica', 'ed1250'),
('software', '8dbbe0')]
delete_url='https://api.github.com/repos/{}/{}/labels/{}'
create_url='https://api.github.com/repos/{}/{}/labels'
# Delete default labels
params = {'access_token':api_key}
for label in labels_to_delete:
resp = requests.delete(delete_url.format(owner, repo, label), params=params)
print(resp.text, resp.status_code)
# Create new labels
for name, color in new_labels:
query = {'name':name, 'color':color}
json_query = json.dumps(query)
resp = requests.post(create_url.format(owner, repo), params=params, data=json_query)
print(resp.text, resp.status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment