-
Notifications
You must be signed in to change notification settings - Fork 3
/
sync.py
executable file
·72 lines (62 loc) · 2.18 KB
/
sync.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
#!/usr/bin/python3
from datetime import datetime, timezone
import github3
import os
import re
import sys
import yaml
def main():
with open('config.yml') as fh:
conf = yaml.safe_load(fh)
token = os.getenv('GITHUB_TOKEN')
assert token
g = github3.login(token=token)
groups = []
for group in conf['groups']:
repos = []
groups.append({
'name': group['name'],
'repos': repos,
})
for desc in group['repos']:
owner, name = desc.split('/')
repo = g.repository(owner=owner, repository=name)
try:
release = repo.latest_release()
except github3.exceptions.NotFoundError:
print(
f"No releases (tags don't count): {desc}",
file=sys.stderr
)
continue
delta = datetime.now(timezone.utc) - release.published_at
compare = repo.compare_commits(
release.tag_name, repo.default_branch
)
nontrivial_commits = len([
c for c in compare.commits()
# not merge commit
if len(c.parents) == 1 and
# not by Dependabot
(c.author is None or c.author.login != 'dependabot[bot]')
])
repos.append({
'repo': desc,
'url': repo.html_url,
'release': re.sub('^[a-z-]+', '', release.tag_name),
'release_url': release.html_url,
'release_date': release.published_at.strftime("%Y-%m-%d"),
'release_days': int(delta.total_seconds() / 86400),
'compare_commits': compare.ahead_by,
'compare_nontrivial': nontrivial_commits,
'compare_url': compare.html_url,
})
with open('docs/_data/repos.yml', 'w') as fh:
yaml.dump({
'groups': groups,
'updated': datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S"),
'green_thresh': conf['thresholds']['green'],
'yellow_thresh': conf['thresholds']['yellow'],
}, fh)
if __name__ == '__main__':
main()