1
1
#!/usr/bin/env python3
2
2
3
- from datetime import datetime
3
+ from datetime import datetime , timedelta
4
4
from typing import Any , Dict , List , Iterable , Optional , Union
5
5
from urllib .request import urlopen , Request
6
6
from urllib .error import HTTPError
@@ -138,7 +138,7 @@ def __init__(self, path, remote='upstream'):
138
138
self .repo_dir = path
139
139
self .remote = remote
140
140
141
- def _run_git_log (self , revision_range ):
141
+ def _run_git_log (self , revision_range ) -> List [ GitCommit ] :
142
142
log = _check_output (["git" , "-C" , self .repo_dir , "log" , '--format=fuller' , '--date=unix' , revision_range ]).split ("\n " )
143
143
rc = []
144
144
cur_msg = []
@@ -285,6 +285,25 @@ def analyze_reverts(commits: List[GitCommit]):
285
285
print (f"{ k } { orig_sm [k ]} ->{ revert_sm [k ]} " )
286
286
287
287
288
+ def print_contributor_stats (commits , delta : Optional [timedelta ] = None ) -> None :
289
+ authors : Dict [str , int ] = {}
290
+ now = datetime .now ()
291
+ # Default delta is one non-leap year
292
+ if delta is None :
293
+ delta = timedelta (days = 365 )
294
+ for commit in commits :
295
+ date , author = commit .commit_date , commit .author
296
+ if now - date > delta :
297
+ break
298
+ if author not in authors :
299
+ authors [author ] = 0
300
+ authors [author ] += 1
301
+
302
+ print (f"{ len (authors )} contributors made { sum (authors .values ())} commits in last { delta .days } days" )
303
+ for count , author in sorted (((commit , author ) for author , commit in authors .items ()), reverse = True ):
304
+ print (f"{ author } : { count } " )
305
+
306
+
288
307
def parse_arguments ():
289
308
from argparse import ArgumentParser
290
309
parser = ArgumentParser (description = "Print GitHub repo stats" )
@@ -293,6 +312,7 @@ def parse_arguments():
293
312
help = "Path to PyTorch git checkout" ,
294
313
default = os .path .expanduser ("~/git/pytorch/pytorch" ))
295
314
parser .add_argument ("--analyze-reverts" , action = "store_true" )
315
+ parser .add_argument ("--contributor-stats" , action = "store_true" )
296
316
return parser .parse_args ()
297
317
298
318
@@ -313,6 +333,8 @@ def main():
313
333
print (f"done in { time .time ()- start_time :.1f} sec" )
314
334
if args .analyze_reverts :
315
335
analyze_reverts (x )
336
+ elif args .contributor_stats :
337
+ print_contributor_stats (x )
316
338
else :
317
339
print_monthly_stats (x )
318
340
0 commit comments