@@ -33,34 +33,53 @@ def updaterepo(project, update=True):
3333 return
3434
3535
36- def retrieve_revision (commit_id , username , project , revision = None ):
37- commit_url = 'https://api.github.com/repos/%s/%s/git/commits/%s' % (
38- username , project , commit_id )
39-
40- commit_json = cache .get (commit_url )
36+ def fetch_json (url ):
37+ json_obj = cache .get (url )
4138
42- if commit_json is None :
39+ if json_obj is None :
4340 try :
44- commit_json = json .load (urllib .urlopen (commit_url ))
41+ json_obj = json .load (urllib .urlopen (url ))
4542 except IOError as e :
4643 logger .exception ("Unable to load %s: %s" ,
47- commit_url , e , exc_info = True )
44+ url , e , exc_info = True )
4845 raise e
4946
50- if commit_json ["message" ] in ("Not Found" , "Server Error" ,):
47+ if "message" in json_obj and \
48+ json_obj ["message" ] in ("Not Found" , "Server Error" ,):
5149 # We'll still cache these for a brief period of time to avoid
5250 # making too many requests:
53- cache .set (commit_url , commit_json , 300 )
51+ cache .set (url , json_obj , 300 )
5452 else :
5553 # We'll cache successes for a very long period of time since
5654 # SCM diffs shouldn't change:
57- cache .set (commit_url , commit_json , 86400 * 30 )
55+ cache .set (url , json_obj , 86400 * 30 )
5856
59- if commit_json ["message" ] in ("Not Found" , "Server Error" ,):
57+ if "message" in json_obj and \
58+ json_obj ["message" ] in ("Not Found" , "Server Error" ,):
6059 raise CommitLogError (
61- "Unable to load %s: %s" % (commit_url , commit_json ["message" ]))
60+ "Unable to load %s: %s" % (url , json_obj ["message" ]))
61+
62+ return json_obj
63+
64+
65+ def retrieve_tag (commit_id , username , project ):
66+ tags_url = 'https://api.github.com/repos/%s/%s/git/refs/tags' % (
67+ username , project )
68+
69+ tags_json = fetch_json (tags_url )
70+ for tag in tags_json :
71+ if tag ['object' ]['sha' ] == commit_id :
72+ return tag ['ref' ].split ("refs/tags/" )[- 1 ]
73+
74+
75+ def retrieve_revision (commit_id , username , project , revision = None ):
76+ commit_url = 'https://api.github.com/repos/%s/%s/git/commits/%s' % (
77+ username , project , commit_id )
78+
79+ commit_json = fetch_json (commit_url )
6280
6381 date = isodate .parse_datetime (commit_json ['committer' ]['date' ])
82+ tag = retrieve_tag (commit_id , username , project )
6483
6584 if revision :
6685 # Overwrite any existing data we might have for this revision since
@@ -82,7 +101,8 @@ def retrieve_revision(commit_id, username, project, revision=None):
82101 'author_email' : commit_json ['author' ]['email' ],
83102 'commitid' : commit_json ['sha' ],
84103 'short_commit_id' : commit_json ['sha' ][0 :7 ],
85- 'parents' : commit_json ['parents' ]}
104+ 'parents' : commit_json ['parents' ],
105+ 'tag' : tag }
86106
87107
88108def getlogs (endrev , startrev ):
0 commit comments