xref: /DragonOS/tools/list_contributors.py (revision b5b571e02693d91eb6918d3b7561e088c3e7ee81)
1# pip install gitpython
2import argparse
3from git import Repo
4import os
5import json
6
7parser = argparse.ArgumentParser(
8    description='List contributors of DragonOS project')
9parser.add_argument('--since', type=str, help='Since date')
10parser.add_argument('--until', type=str, help='Until date')
11parser.add_argument('--mode', type=str, help='脚本的运行模式 可选:<all> 输出所有信息\n' +
12                    ' <short> 输出贡献者名单、邮箱以及提交数量', default='all')
13args = parser.parse_args()
14
15repo = Repo(os.path.dirname(os.path.realpath(__file__)) + "/..")
16
17# Get the list of contributors
18
19format = '--pretty={"commit":"%h", "author":"%an", "email":"%ae", "date":"%cd"}'
20
21logs = repo.git.log(format, since=args.since, until=args.until)
22
23
24if args.mode == 'all':
25    print(logs)
26elif args.mode == 'short':
27    logs = logs.splitlines()
28    print("指定时间范围内总共有", len(logs), "次提交")
29    logs = [json.loads(line) for line in logs]
30    print("贡献者名单:")
31
32    authors = dict()
33    for line in logs:
34        if line['email'] not in authors.keys():
35            authors[line['email']] = {
36                'author': line['author'],
37                'email': line['email'],
38                'count': 1
39            }
40        else:
41            authors[line['email']]['count'] += 1
42
43    # 排序输出
44    authors = sorted(authors.values(), key=lambda x: x['count'], reverse=True)
45    for author in authors:
46        print(author['author'], author['email'], author['count'])
47