-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-labels.py
79 lines (65 loc) · 2.53 KB
/
create-labels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
This script removes default github labels and adds custom ones using python requests and the github API
To work it needs:
1) User token
2) Target username / organization name
3) Target repository name and the
By Pablo and Spearbit with <3
License: MIT
"""
import requests
def delete_default_labels():
default_labels = [
"bug",
"duplicate",
"enhancement",
"invalid",
"question",
"wontfix",
"question",
"good first issue",
"help wanted",
"documentation"
]
for i in default_labels:
r = requests.delete(f"https://api.github.com/repos/{username}/{repo}/labels/{i}", headers=headers)
print(f"Deleting {i}... Github API ", r)
print("Done deleting default labels!\n")
def create_new_labels():
labels = [
{ "name": "Severity: Critical Risk", "color": "ff0000"},
{ "name": "Severity: High Risk" , "color": "B60205"},
{ "name": "Severity: Medium Risk" , "color": "D93F0B"},
{ "name": "Severity: Low Risk", "color": "FBCA04"},
{ "name": "Severity: Informational" , "color": "1D76DB"},
{ "name": "Severity: Gas Optimization", "color": "B4E197"},
{ "name": "Status: Acknowledged", "color": "5319E7"},
{ "name": "Status: Fixed", "color": "0E8A16"},
{ "name": "Status: ReadyForReport", "color": "bfdadc"},
{ "name": "Monitoring ☎: ", "color": "FBCA04", "description": "Invariants and areas for monitoring"}
]
i = 0
for data in labels:
r = requests.post(f"https://api.github.com/repos/{username}/{repo}/labels", headers=headers, json=data)
print(f"Creating new label {data}... Github API {r}")
i+=1
print("Done creating new labels!\n")
# __ MAIN __
print("Hello! This script will first delete all labels from the target repository and create custom ones. Please enter the following details:\n")
while(True):
token = input(str("1) Access token: "))
username = input(str("2) User / Organization name: "))
repo = input(str("3) Target repo name: "))
if token != "" and repo != "" and username != "":
break
print("Please fill in the details.")
headers = {
"Authorization": f"token {token}",
"Accept": "application/vnd.github.v3+json",
"User-Agent": "request"
}
url = f"https://api.github.com/repos/{username}/{repo}/labels"
print(f"Deleting default labels in: {url}...\n")
delete_default_labels()
create_new_labels()
print("Please confirm old labels have been deleted and new ones have been created.")