-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlabels.py
More file actions
55 lines (45 loc) · 1.93 KB
/
Copy pathlabels.py
File metadata and controls
55 lines (45 loc) · 1.93 KB
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
import json
import os
import sys
from urllib.parse import quote
if __name__ == '__main__':
if len(sys.argv) != 6:
print("python labels.py owner repo user passwd action[create/update/get/delete]")
exit(1)
owner = sys.argv[1]
repo = sys.argv[2]
user = sys.argv[3]
passwd = sys.argv[4]
action = sys.argv[5]
labels = None
with open('github.json', 'r') as f:
labels = map(lambda l: dict(name=l['name'], color=l['color'], description=l['description']), json.loads(f.read()))
for label in labels:
data = json.dumps(label, ensure_ascii=False)
cmd = None
if 'create' == action:
cmd = 'curl -u {0}:{1} \
-H "Accept: application/vnd.github.symmetra-preview+json" \
-d \'{4}\' \
https://api.github.com/repos/{2}/{3}/labels'.format(user, passwd, owner, repo, data)
elif 'update' == action:
cmd = 'curl -u {0}:{1} \
-H "Accept: application/vnd.github.symmetra-preview+json" \
-d \'{4}\' \
-X PATCH \
https://api.github.com/repos/{2}/{3}/labels/{5}'.format(user, passwd, owner, repo, data, quote(label['name']))
elif 'get' == action:
cmd = 'curl -u {0}:{1} \
-H "Accept: application/vnd.github.symmetra-preview+json" \
https://api.github.com/repos/{2}/{3}/labels > github.json'.format(user, passwd, owner, repo)
print(cmd)
os.system(cmd)
break
elif 'delete' == action:
cmd = 'curl -u {0}:{1} \
-H "Accept: application/vnd.github.symmetra-preview+json" \
-X DELETE\
https://api.github.com/repos/{2}/{3}/labels/{4}'.format(user, passwd, owner, repo, quote(label['name']))
if cmd is not None:
print(cmd)
os.system(cmd)