-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-sync-labels
executable file
·107 lines (90 loc) · 3.88 KB
/
github-sync-labels
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
from github import Github
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--user", help="github.com user name")
parser.add_argument("-p", "--password", help="github.com password")
parser.add_argument("-n", "--dry-run", action="store_true", help="Only show what would be modified without actually doing so")
args = parser.parse_args()
g = Github(args.user, args.password)
GITHUB_DEFAULT_LABELS = ["bug", "duplicate", "enhancement", "help wanted", "invalid", "question", "wontfix",
"good first issue"]
CHIMERA_TK_DEFAULT_LABELS = {
"longterm": [
"Long term task which might result in subtasks and requires significant design planning",
"c5def5"
],
"readyForImplementation": [
'This ticket has been moved to the "ready for implementation" area on the MSK software group board',
"fbca04"
],
"selected": [
"This ticket has been selected for the MSK software group board",
"00eeee"
],
"umbrella": [
"Meta ticket which just provides a framework for subtickets which together form a bigger task",
"0052cc"
],
"umbrellaChild": [
"Child ticked generated from an umbrella ticket",
"bfdadc"
],
"urgent": [
"High priority ticket",
"b60205"
],
"postponed": [
"A ticket that has might have been postponed from being worked on for various reasons",
"eeee00"
],
"review" : [
"A ticket that has been finished and should be reviewed by another developer",
"918ae2"
]
}
def sort_by_name(arg):
return sorted(arg, key=lambda x: x.name)
org = g.get_organization("ChimeraTK")
for repo in sort_by_name(org.get_repos()):
print(repo.name)
missing_labels = list(CHIMERA_TK_DEFAULT_LABELS.keys())
extra_labels = []
to_modify = []
for label in sort_by_name(repo.get_labels()):
if label.name in GITHUB_DEFAULT_LABELS:
continue
description = None
try:
description = label.description
except AttributeError:
pass
if label.name in CHIMERA_TK_DEFAULT_LABELS:
missing_labels.remove(label.name)
expected = CHIMERA_TK_DEFAULT_LABELS[label.name]
if label.color != expected[1] or description != expected[0]:
to_modify.append(label)
if label.color != expected[1]:
print(" {} exists but has unexpected color: \"{}\" (expected \"{}\")".format(label.name, label.color,
expected[1]))
if description != expected[0]:
print(" {} exists but has unexpected description: \"{}\" (expected \"{}\")".format(label.name,
description,
expected[0]))
else:
extra_labels.append(label.name)
if len(missing_labels) > 0:
print(" Labels missing in this repository: {}".format(repr(missing_labels)))
for label in missing_labels:
print(" Adding " + label)
if not args.dry_run:
repo.create_label(label, CHIMERA_TK_DEFAULT_LABELS[label][1], CHIMERA_TK_DEFAULT_LABELS[label][0])
if len(extra_labels) > 0:
print(" Extra labels in this repository: {}".format(repr(extra_labels)))
if len(to_modify) > 0:
print(" Labels that need modification: {}".format(repr([label.name for label in to_modify])))
for label in to_modify:
print(" Modifying " + label.name)
if not args.dry_run:
label.edit(label.name, CHIMERA_TK_DEFAULT_LABELS[label.name][1], CHIMERA_TK_DEFAULT_LABELS[label.name][0])
print()