1919logger = logging .getLogger (__name__ )
2020
2121GITHUB_URL_RE = re .compile (
22- r'^(?P<proto>\w+)://github.com/(?P<username>[^/]+)/(?P<project>[^/]+)[.]git$' )
22+ r'^(?P<proto>\w+)://github.com/(?P<username>[^/]+)/(?P<project>[^/]+)( [.]git)? $' )
2323
2424# We currently use a simple linear search of on a single parent to retrieve
2525# the history. This is often good enough, but might miss the actual starting
@@ -33,7 +33,7 @@ def updaterepo(project, update=True):
3333
3434
3535def retrieve_revision (commit_id , username , project , revision = None ):
36- commit_url = 'http ://github.com/api/v2/json/commits/show/ %s/%s/%s' % (
36+ commit_url = 'https ://api. github.com/repos/ %s/%s/git/commits /%s' % (
3737 username , project , commit_id )
3838
3939 commit_json = cache .get (commit_url )
@@ -46,20 +46,18 @@ def retrieve_revision(commit_id, username, project, revision=None):
4646 commit_url , e , exc_info = True )
4747 raise e
4848
49- if 'error' in commit_json :
49+ if commit_json [ "message" ] in ( "Not Found" , "Server Error" ,) :
5050 # We'll still cache these for a brief period of time to avoid making too many requests:
5151 cache .set (commit_url , commit_json , 300 )
5252 else :
5353 # We'll cache successes for a very long period of time since
5454 # SCM diffs shouldn't change:
5555 cache .set (commit_url , commit_json , 86400 * 30 )
5656
57- if 'error' in commit_json :
58- raise RuntimeError ("Unable to load %s: %s" % (commit_url , commit_json ['error' ]))
57+ if commit_json [ "message" ] in ( "Not Found" , "Server Error" ,) :
58+ raise RuntimeError ("Unable to load %s: %s" % (commit_url , commit_json ["message" ]))
5959
60- commit = commit_json ['commit' ]
61-
62- date = isodate .parse_datetime (commit ['committed_date' ])
60+ date = isodate .parse_datetime (commit_json ['committer' ]['date' ])
6361
6462 if revision :
6563 # Overwrite any existing data we might have for this revision since
@@ -68,19 +66,19 @@ def retrieve_revision(commit_id, username, project, revision=None):
6866 # We need to convert the timezone-aware date to a naive (i.e.
6967 # timezone-less) date in UTC to avoid killing MySQL:
7068 revision .date = date .astimezone (isodate .tzinfo .Utc ()).replace (tzinfo = None )
71- revision .author = commit ['author' ]['name' ]
72- revision .message = commit ['message' ]
69+ revision .author = commit_json ['author' ]['name' ]
70+ revision .message = commit_json ['message' ]
7371 revision .full_clean ()
7472 revision .save ()
7573
7674 return {'date' : date ,
77- 'message' : commit ['message' ],
75+ 'message' : commit_json ['message' ],
7876 'body' : "" , # TODO: pretty-print diffs
79- 'author' : commit ['author' ]['name' ],
80- 'author_email' : commit ['author' ]['email' ],
81- 'commitid' : commit [ 'id ' ],
82- 'short_commit_id' : commit [ 'id ' ][0 :7 ],
83- 'parents' : commit ['parents' ]}
77+ 'author' : commit_json ['author' ]['name' ],
78+ 'author_email' : commit_json ['author' ]['email' ],
79+ 'commitid' : commit_json [ 'sha ' ],
80+ 'short_commit_id' : commit_json [ 'sha ' ][0 :7 ],
81+ 'parents' : commit_json ['parents' ]}
8482
8583
8684def getlogs (endrev , startrev ):
@@ -90,6 +88,9 @@ def getlogs(endrev, startrev):
9088 else :
9189 revisions = [i for i in (startrev , endrev ) if i .commitid ]
9290
91+ if endrev .branch .project .repo_path [- 1 ] == '/' :
92+ endrev .branch .project .repo_path = endrev .branch .project .repo_path [:- 1 ]
93+
9394 m = GITHUB_URL_RE .match (endrev .branch .project .repo_path )
9495
9596 if not m :
@@ -110,16 +111,16 @@ def getlogs(endrev, startrev):
110111 last_rev_data = retrieve_revision (revision .commitid , username , project , revision )
111112 logs .append (last_rev_data )
112113 revision_count += 1
113- ancestor_found = (startrev .commitid in [rev ['id ' ] for rev in last_rev_data ['parents' ]])
114+ ancestor_found = (startrev .commitid in [rev ['sha ' ] for rev in last_rev_data ['parents' ]])
114115
115116 # Simple approach to find the startrev, stop after found or after
116117 # #GITHUB_REVISION_LIMIT revisions are fetched
117118 while (revision_count < GITHUB_REVISION_LIMIT
118119 and not ancestor_found
119120 and len (last_rev_data ['parents' ]) > 0 ):
120- last_rev_data = retrieve_revision (last_rev_data ['parents' ][0 ]['id ' ], username , project )
121+ last_rev_data = retrieve_revision (last_rev_data ['parents' ][0 ]['sha ' ], username , project )
121122 logs .append (last_rev_data )
122123 revision_count += 1
123- ancestor_found = (startrev .commitid in [rev ['id ' ] for rev in last_rev_data ['parents' ]])
124+ ancestor_found = (startrev .commitid in [rev ['sha ' ] for rev in last_rev_data ['parents' ]])
124125
125126 return sorted (logs , key = lambda i : i ['date' ], reverse = True )
0 commit comments