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