|
| 1 | +# pip install gitpython |
| 2 | +import argparse |
| 3 | +import sys |
| 4 | +from git import Repo |
| 5 | +import os |
| 6 | +import json |
| 7 | + |
| 8 | +parser = argparse.ArgumentParser( |
| 9 | + description='List contributors of DragonOS project') |
| 10 | +parser.add_argument('--since', type=str, help='Since date') |
| 11 | +parser.add_argument('--until', type=str, help='Until date') |
| 12 | +parser.add_argument('--mode', type=str, help='脚本的运行模式 可选:<all> 输出所有信息\n' + |
| 13 | + ' <short> 输出贡献者名单、邮箱以及提交数量', default='all') |
| 14 | +args = parser.parse_args() |
| 15 | + |
| 16 | +repo = Repo(os.path.dirname(os.path.realpath(__file__)) + "/..") |
| 17 | + |
| 18 | +# Get the list of contributors |
| 19 | + |
| 20 | +format = '--pretty={"commit":"%h", "author":"%an", "email":"%ae", "date":"%cd"}' |
| 21 | + |
| 22 | +logs = repo.git.log(format, since=args.since, until=args.until) |
| 23 | + |
| 24 | + |
| 25 | +if args.mode == 'all': |
| 26 | + print(logs) |
| 27 | +elif 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']) |
0 commit comments