Skip to content

Commit 831e13c

Browse files
authored
Merge pull request tobami#207 from octmoraru/tag_save
Tag saving features
2 parents 17cba4b + 8fb7f1f commit 831e13c

7 files changed

Lines changed: 71 additions & 25 deletions

File tree

codespeed/commits/git.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,21 @@ def getlogs(endrev, startrev):
6666
(short_commit_id, commit_id, date_t, author_name, author_email,
6767
subject, body) = log.split("\x00", 7)
6868

69+
tag = ""
70+
71+
cmd = ["git", "describe", "--tags", commit_id]
72+
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, cwd=working_copy)
73+
74+
stdout, stderr = p.communicate()
75+
76+
if p.returncode == 0:
77+
tag = stdout
78+
6979
date = datetime.datetime.fromtimestamp(
7080
int(date_t)).strftime("%Y-%m-%d %H:%M:%S")
7181

7282
logs.append({'date': date, 'message': subject, 'commitid': commit_id,
7383
'author': author_name, 'author_email': author_email,
74-
'body': body, 'short_commit_id': short_commit_id})
84+
'body': body, 'short_commit_id': short_commit_id, 'tag': tag})
7585

7686
return logs

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):

codespeed/commits/mercurial.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def getlogs(endrev, startrev):
5050

5151
cmd = ["hg", "log",
5252
"-r", "%s::%s" % (startrev.commitid, endrev.commitid),
53-
"--template", "{rev}:{node|short}\n{node}\n{author|user}\n{author|email}\n{date}\n{desc}\n=newlog=\n"]
53+
"--template", "{rev}:{node|short}\n{node}\n{author|user}\n{author|email}\n{date}\n{tags}\n{desc}\n=newlog=\n"]
5454

5555
working_copy = endrev.branch.project.working_copy
5656
p = Popen(cmd, stdout=PIPE, stderr=PIPE, cwd=working_copy)
@@ -64,7 +64,7 @@ def getlogs(endrev, startrev):
6464
for log in stdout.split("=newlog=\n"):
6565
elements = []
6666
elements = log.split('\n')[:-1]
67-
if len(elements) < 6:
67+
if len(elements) < 7:
6868
# "Malformed" log
6969
logs.append(
7070
{'date': '-', 'message': 'error parsing log', 'commitid': '-'})
@@ -74,6 +74,8 @@ def getlogs(endrev, startrev):
7474
author_name = elements.pop(0)
7575
author_email = elements.pop(0)
7676
date = elements.pop(0)
77+
tag = elements.pop(0)
78+
tag = "" if tag == "tip" else tag
7779
# All other newlines should belong to the description text. Join.
7880
message = '\n'.join(elements)
7981

@@ -85,7 +87,7 @@ def getlogs(endrev, startrev):
8587
logs.append({
8688
'date': date, 'author': author_name,
8789
'author_email': author_email, 'message': message,
88-
'short_commit_id': short_commit_id, 'commitid': commit_id})
90+
'short_commit_id': short_commit_id, 'commitid': commit_id, 'tag': tag})
8991
# Remove last log here because mercurial saves the short hast as commitid now
9092
if len(logs) > 1 and logs[-1].get('short_commit_id') == startrev.commitid:
9193
logs.pop()

codespeed/commits/subversion.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ def updaterepo(project):
1313
return [{'error': False}]
1414

1515

16+
def get_tag(rev_num, repo_path, client):
17+
tags_url = repo_path + '/tags'
18+
tags = client.ls(tags_url)
19+
20+
for tag in tags:
21+
if 'created_rev' in tag and tag['created_rev'].number == rev_num:
22+
if 'name' in tag:
23+
return tag['name'].split('/')[-1]
24+
return ''
25+
26+
1627
def getlogs(newrev, startrev):
1728
import pysvn
1829

@@ -56,8 +67,10 @@ def get_login(realm, username, may_save):
5667
author = ""
5768
date = datetime.fromtimestamp(log.date).strftime("%Y-%m-%d %H:%M:%S")
5869
message = log.message
70+
tag = get_tag(log.revision.number,
71+
newrev.branch.project.repo_path, client)
5972
# Add log unless it is the last commit log, which has already been tested
6073
logs.append({
6174
'date': date, 'author': author, 'message': message,
62-
'commitid': log.revision.number})
75+
'commitid': log.revision.number, 'tag': tag})
6376
return logs

codespeed/results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def save_result(data):
9797
rev.author = log['author']
9898
rev.date = log['date']
9999
rev.message = log['message']
100+
rev.tag = log['tag']
100101

101102
rev.save()
102103

codespeed/static/js/timeline.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ function getHighlighterConfig(median) {
8282
return {
8383
show: true,
8484
tooltipLocation: 'nw',
85-
yvalues: 7,
86-
formatString:'<table class="jqplot-highlighter"> <tr><td>date:</td><td>%s</td></tr> <tr><td>median:</td><td>%s</td></tr> <tr><td>max:</td><td>%s</td></tr> <tr><td>Q3:</td><td>%s</td></tr> <tr><td>Q1:</td><td>%s</td></tr> <tr><td>min:</td><td>%s</td></tr> <tr><td>commit:</td><td>%s</td></tr></table>'
85+
yvalues: 8,
86+
formatString:'<table class="jqplot-highlighter"> <tr><td>date:</td><td>%s</td></tr> <tr><td>median:</td><td>%s</td></tr> <tr><td>max:</td><td>%s</td></tr> <tr><td>Q3:</td><td>%s</td></tr> <tr><td>Q1:</td><td>%s</td></tr> <tr><td>min:</td><td>%s</td></tr> <tr><td>commit:</td><td>%s</td></tr><tr><td>tag:</td><td>%s</td></tr></table>'
8787
};
8888
} else {
8989
return {
9090
show: true,
9191
tooltipLocation: 'nw',
92-
yvalues: 4,
93-
formatString:'<table class="jqplot-highlighter"> <tr><td>date:</td><td>%s</td></tr> <tr><td>result:</td><td>%s</td></tr> <tr><td>std dev:</td><td>%s</td></tr> <tr><td>commit:</td><td>%s</td></tr></table>'
92+
yvalues: 5,
93+
formatString:'<table class="jqplot-highlighter"> <tr><td>date:</td><td>%s</td></tr> <tr><td>result:</td><td>%s</td></tr> <tr><td>std dev:</td><td>%s</td></tr> <tr><td>commit:</td><td>%s</td></tr><tr><td>tag:</td><td>%s</td></tr></table>'
9494
};
9595
}
9696
}

codespeed/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def gettimelinedata(request):
306306
[
307307
res.revision.date.strftime('%Y/%m/%d %H:%M:%S %z'),
308308
res.value, val_max, q3, q1, val_min,
309-
res.revision.get_short_commitid(), branch
309+
res.revision.get_short_commitid(), res.revision.tag, branch
310310
]
311311
)
312312
else:
@@ -317,7 +317,7 @@ def gettimelinedata(request):
317317
[
318318
res.revision.date.strftime('%Y/%m/%d %H:%M:%S %z'),
319319
res.value, std_dev,
320-
res.revision.get_short_commitid(), branch
320+
res.revision.get_short_commitid(), res.revision.tag, branch
321321
]
322322
)
323323
timeline['branches'][branch][executable] = results

0 commit comments

Comments
 (0)