-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlistcontrib
executable file
·84 lines (66 loc) · 2.11 KB
/
listcontrib
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
#!/usr/bin/env python
import json
import requests
import tomlkit
import io
def get_commit_emails(owner, repo, token=None):
base_url = f"https://api.github.com/repos/{owner}/{repo}/commits"
headers = {'Authorization': f'token {token}'} if token else {}
page = 1
emails = set()
while True:
url = f"{base_url}?per_page=100&page={page}"
response = requests.get(url, headers=headers)
data = response.json()
if response.status_code != 200 or not data:
break
for commit in data:
if 'commit' in commit:
author = commit['commit']['author']
print(author)
if 'email' in author:
emails.add(author['email'])
page += 1
return json.dumps(list(emails), indent=2)
def getcontribinfo(theurl):
content = requests.get(theurl)
data = json.loads(content.content)
try:
thename = data['name']
except KeyError:
return None
else:
return thename
theurl = 'https://api.github.com/repos/bbfrederick/rapidtide/contributors?anon=1'
content = requests.get(theurl)
data = json.loads(content.content)
contriblist = []
for theitem in data:
print(theitem)
try:
contriburl = theitem['url']
except KeyError:
pass
else:
thename = getcontribinfo(contriburl)
if thename is not None:
contriblist.append({"name": thename})
with open("pyproject.toml") as stream:
try:
pyproject_loaded = tomlkit.load(stream)
except tomlkit.TOMLError as exc:
print(exc)
#print(get_commit_emails("bbfrederick", "rapidtide"))
# remove the existing authors field
pyproject_loaded["project"].pop("authors")
# create a properly formatted contriblist
authoritem = tomlkit.array()
for contrib in contriblist:
authoritem.add_line(contrib)
authoritem.add_line(indent="")
print(authoritem.as_string())
# now add it
pyproject_loaded["project"].append("authors", authoritem)
# Write TOML file
with io.open('test.toml', 'w', encoding='utf8') as outfile:
tomlkit.dump(pyproject_loaded, outfile)