28
28
from github3 .repos .download import Download
29
29
from github3 .repos .hook import Hook
30
30
from github3 .repos .status import Status
31
+ from github3 .repos .stats import ContributorStats
31
32
from github3 .repos .tag import RepoTag
32
33
from github3 .users import User , Key
33
34
@@ -848,6 +849,28 @@ def iter_branches(self, number=-1, etag=None):
848
849
url = self ._build_url ('branches' , base_url = self ._api )
849
850
return self ._iter (int (number ), url , Branch , etag = etag )
850
851
852
+ def iter_code_frequency (self , number = - 1 , etag = None ):
853
+ """Iterate over the code frequency per week.
854
+
855
+ Returns a weekly aggregate of the number of additions and deletions
856
+ pushed to this repository.
857
+
858
+ :param int number: (optional), number of weeks to return. Default: -1
859
+ returns all weeks
860
+ :param str etag: (optional), ETag from a previous request to the same
861
+ endpoint
862
+ :returns: generator of lists ``[seconds_from_epoch, additions,
863
+ deletions]``
864
+
865
+ .. note:: All statistics methods may return a 202. On those occasions,
866
+ you will not receive any objects. You should store your
867
+ iterator and check the new ``last_status`` attribute. If it
868
+ is a 202 you should wait before re-requesting.
869
+
870
+ """
871
+ url = self ._build_url ('stats' , 'code_frequecy' , base_url = self ._api )
872
+ return self ._iter (int (number ), url , list , etag = etag )
873
+
851
874
def iter_comments (self , number = - 1 , etag = None ):
852
875
"""Iterate over comments on all commits in the repository.
853
876
@@ -874,6 +897,26 @@ def iter_comments_on_commit(self, sha, number=1, etag=None):
874
897
url = self ._build_url ('commits' , sha , 'comments' , base_url = self ._api )
875
898
return self ._iter (int (number ), url , RepoComment , etag = etag )
876
899
900
+ def iter_commit_activity (self , number = - 1 , etag = None ):
901
+ """Iterate over last year of commit activity by week.
902
+
903
+ See: http://developer.github.com/v3/repos/statistics/
904
+
905
+ :param int number: (optional), number of weeks to return. Default -1
906
+ will return all of the weeks.
907
+ :param str etag: (optional), ETag from a previous request to the same
908
+ endpoint
909
+ :returns: generator of dictionaries
910
+
911
+ .. note:: All statistics methods may return a 202. On those occasions,
912
+ you will not receive any objects. You should store your
913
+ iterator and check the new ``last_status`` attribute. If it
914
+ is a 202 you should wait before re-requesting.
915
+
916
+ """
917
+ url = self ._build_url ('stats' , 'commit_activity' , base_url = self ._api )
918
+ return self ._iter (int (number ), url , dict , etag = etag )
919
+
877
920
def iter_commits (self , sha = None , path = None , author = None , number = - 1 ,
878
921
etag = None ):
879
922
"""Iterate over commits in this repository.
@@ -912,6 +955,27 @@ def iter_contributors(self, anon=False, number=-1, etag=None):
912
955
params = {'anon' : True }
913
956
return self ._iter (int (number ), url , User , params , etag )
914
957
958
+ def iter_contributor_statistics (self , number = - 1 , etag = None ):
959
+ """Iterate over the contributors list.
960
+
961
+ See also: http://developer.github.com/v3/repos/statistics/
962
+
963
+ :param int number: (optional), number of weeks to return. Default -1
964
+ will return all of the weeks.
965
+ :param str etag: (optional), ETag from a previous request to the same
966
+ endpoint
967
+ :returns: generator of
968
+ :class:`ContributorStats <github3.repos.stats.ContributorStats>`
969
+
970
+ .. note:: All statistics methods may return a 202. On those occasions,
971
+ you will not receive any objects. You should store your
972
+ iterator and check the new ``last_status`` attribute. If it
973
+ is a 202 you should wait before re-requesting.
974
+
975
+ """
976
+ url = self ._build_url ('stats' , 'contributors' , base_url = self ._api )
977
+ return self ._iter (int (number ), url , ContributorStats , etag = etag )
978
+
915
979
def iter_downloads (self , number = - 1 , etag = None ):
916
980
"""Iterate over available downloads for this repository.
917
981
@@ -1398,3 +1462,27 @@ def update_label(self, name, color, new_name=''):
1398
1462
upd = label .update
1399
1463
resp = upd (new_name , color ) if new_name else upd (name , color )
1400
1464
return resp
1465
+
1466
+ def weekly_commit_count (self ):
1467
+ """Returns the total commit counts.
1468
+
1469
+ The dictionary returned has two entries: ``all`` and ``owner``. Each
1470
+ has a fifty-two element long list of commit counts. (Note: ``all``
1471
+ includes the owner.) ``d['all'][0]`` will be the oldest week,
1472
+ ``d['all'][51]`` will be the most recent.
1473
+
1474
+ :returns: dict
1475
+
1476
+ .. note:: All statistics methods may return a 202. If github3.py
1477
+ receives a 202 in this case, it will return an emtpy dictionary.
1478
+ You should give the API a moment to compose the data and then re
1479
+ -request it via this method.
1480
+
1481
+ """
1482
+ url = self ._build_url ('stats' , 'participation' , base_url = self ._api )
1483
+ resp = self ._get (url )
1484
+ if resp .status_code == 202 :
1485
+ return {}
1486
+ json = self ._json (resp , 200 )
1487
+ del (json ['Etag' ], json ['Last-Modified' ])
1488
+ return json
0 commit comments