-
Notifications
You must be signed in to change notification settings - Fork 14
/
get_release_stats.py
executable file
·73 lines (54 loc) · 2.5 KB
/
get_release_stats.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
73
#!/usr/bin/env python3
"""
Based on https://pagure.io/github-release-stats/blob/master/f/get_release_stats.py by Clement Verna.
This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator
SPDX-FileCopyrightText: 2024 Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
SPDX-License-Identifier: GPL-3.0-or-later
"""
import itertools
import re
from operator import itemgetter
from github import Github
def compute_average(issues_date: list[tuple[int, int]]) -> float:
sum_of_issues = sum(days for _issue, days in issues_date)
if len(issues_date):
return sum_of_issues / len(issues_date)
return sum_of_issues
def main() -> None:
api_token = None
gh = Github(api_token)
repo = gh.get_repo("ArduPilot/MethodicConfigurator")
last_5_releases = itertools.islice(repo.get_releases(), 5)
overall_issues = []
unique_issues = set()
for repo_release in last_5_releases:
release = repo.get_release(repo_release.id)
# Date of the release
release_date = release.created_at
# Find all the issue references in the release notes
release_issues = re.findall(r"#\d+", release.body)
issues_date = []
for issue in release_issues:
# Remove the # char from the issue number and convert to int
# then get the issue creation date
date = repo.get_issue(int(issue[1:])).created_at
number_days = release_date - date
if issue not in unique_issues:
issues_date.append((issue, number_days.days))
unique_issues.add(issue)
overall_issues.append(number_days.days)
print(f"{release.title} ({release_date})")
print("---------------------------------")
if issues_date:
print(f"Number of issues : {len(issues_date)}")
print(f"Days to release issue (Average) : {compute_average(issues_date)}")
print(f"Days to release issue (Maximun) : {max(issues_date, key=itemgetter(1))[1]}")
print(f"Days to release issue (Minimun) : {min(issues_date, key=itemgetter(1))[1]}")
total_downloads = sum(asset.download_count for asset in release.get_assets())
print(f"Total downloads : {total_downloads}")
print("---------------------------------\n")
# print(issues_date)
if overall_issues:
print(f"Average of days to release an issue over 5 releases : {sum(overall_issues) / len(overall_issues)}")
if __name__ == "__main__":
main()