Skip to content

Commit 5363a4c

Browse files
committed
Retrieve tag information using the GitHub API
Get the list of all (i.e. lightweight, annotated) tags and search for the given commit id. If found, add it to the dictionary returned by 'getlogs'.
1 parent 39e3e81 commit 5363a4c

1 file changed

Lines changed: 34 additions & 14 deletions

File tree

codespeed/commits/github.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

88108
def getlogs(endrev, startrev):

0 commit comments

Comments
 (0)