/
update_contributors.py
65 lines (43 loc) · 1.52 KB
/
update_contributors.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
import requests
import sys
import json
s = requests.Session()
s.trust_env = False
repo = "unimath/agda-unimath"
url = f"https://api.github.com/repos/{repo}/contributors"
response = s.get(url)
if response.status_code != 200:
print(f"Failed to retrieve contributors for repository {repo}. "
f"Status code: {response.status_code}", file=sys.stderr)
exit(1)
contributors = json.loads(response.text)
template = """
## Contributors
We are grateful to the following people for their contributions to
the library.
Name 1
Help us to improve the library by contributing to the project!
Contributions come in many forms, please ask us if you are not sure
how to help. We are happy to help you get started.
"""
def get_github_user_name(username):
url = f"https://api.github.com/users/{username}"
response = s.get(url)
if response.status_code != 200:
print(f"Failed to retrieve information for user {username}. "
f"Status code: {response.status_code}", file=sys.stderr)
return ""
user_info = json.loads(response.text)
name = user_info.get('name', '')
return name
contributors_list = []
for contributor in contributors:
login = contributor['login']
html_url = contributor['html_url']
name = get_github_user_name(login)
if name is None or name == "":
name = login
contributors_list.append(f"- [{name}]({html_url})")
output = template.replace("Name 1", "\n".join(contributors_list))
with open("CONTRIBUTORS.md", "w") as file:
file.write(output)