-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
release.py
69 lines (57 loc) · 1.92 KB
/
release.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
import datetime
import json
import os
import sys
from github import Github
from github.GithubException import UnknownObjectException as GithubUnknownObjectException
g = Github(os.environ['GITHUB_TOKEN'], per_page=100)
class NoReleasesFound(Exception):
pass
class Repo:
def __init__(self, repo):
self.repo = repo
self.releases = self.repo.get_releases()
if self.releases.totalCount == 0:
raise NoReleasesFound
self.last_release_timestamp = self.releases[0].created_at.timestamp()
self.default_branch = self.repo.default_branch
self.commits = self.repo.get_commits(since=self.releases[0].created_at,sha=self.default_branch)
org = g.get_organization('elementary')
repos = []
for repo in org.get_repos(sort="full_name"):
if repo.archived is False:
print ('Processing {}...'.format(repo.name))
try:
repos.append(Repo(repo))
# This catches repos that don't have releases and ignores them
except NoReleasesFound:
pass
repos = sorted(repos, key=lambda repo: repo.last_release_timestamp, reverse=True)
json_out = []
for repo in repos:
new_commits = 0
try:
# Remove 1 commit, since the release commit itself seems to get included
new_commits = repo.commits.totalCount - 1
if new_commits < 0:
new_commits = 0
except GithubUnknownObjectException:
pass
releases = []
for release in repo.releases:
release_date = datetime.datetime.fromtimestamp(repo.last_release_timestamp).strftime("%Y-%m-%d")
releases.append ({
"version": release.tag_name,
"release_date": release.created_at.isoformat(),
"title": release.title,
"body": release.body,
"href": release.html_url
})
json_out.append ({
"name": repo.repo.name,
"releases": releases,
"new_commits": new_commits,
"default_branch": repo.default_branch
})
with open('_data/repos.json', 'w') as outfile:
json.dump(json_out, outfile, indent=2, ensure_ascii=False)