Debian Codegraph @

dev/tools/repo_stats.py

raw
1 import collections
2 import datetime
3 import os
4
5 try:
6 from github import Github
7 except ImportError:
8 raise ImportError('Install PyGithub from https://github.com/PyGithub/PyGithub or via pip')
9 API_TOKEN = os.environ.get('GITHUB_API_TOKEN', None)
10 if API_TOKEN is None:
11 raise ValueError('Need to specify an API token')
12
13 p = Github(API_TOKEN)
14 last_release = datetime.datetime(year=2024, month=7, day=1)
15 authors = []
16 comments = p.get_repo('brian-team/brian2').get_issues_comments(since=last_release)
17 comment_counter = 0
18 for comment in comments:
19 name = comment.user.name
20 if name is None:
21 authors.append('`@{login} <https://github.com/{login}>`_'.format(login=comment.user.login))
22 else:
23 authors.append(
24 '{name} (`@{login} <https://github.com/{login}>`_)'.format(
25 login=comment.user.login,
26 name=name))
27 comment_counter += 1
28 print('Counted {} comments'.format(comment_counter))
29
30 issues = p.get_repo('brian-team/brian2').get_issues(since=last_release)
31 issue_counter = 0
32 for issue in issues:
33 name = issue.user.name
34 if name is None:
35 authors.append('`@{login} <https://github.com/{login}>`_'.format(login=issue.user.login))
36 else:
37 authors.append(
38 '{name} (`@{login} <https://github.com/{login}>`_)'.format(
39 login=issue.user.login,
40 name=name))
41 issue_counter += 1
42 print('Counted {} issues'.format(issue_counter))
43
44 counted = collections.Counter(authors)
45 sorted = sorted(counted.items(), key=lambda item: item[1], reverse=True)
46 for name, contributions in sorted:
47 print('{:>4} {}'.format(contributions, name))