Skip to content

Commit 47b6477

Browse files
committed
Adjust gettimelines to work properly with default_branch
1 parent b4a8882 commit 47b6477

File tree

3 files changed

+57
-41
lines changed

3 files changed

+57
-41
lines changed

codespeed/fixtures/timeline_tests.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"repo_user": "",
3838
"track": false,
3939
"repo_pass": "",
40-
"repo_path": ""
40+
"repo_path": "",
41+
"default_branch": "master"
4142
}
4243
},
4344
{
@@ -61,7 +62,7 @@
6162
"model": "codespeed.branch",
6263
"fields": {
6364
"project": 2,
64-
"name": "master"
65+
"name": "default"
6566
}
6667
},
6768
{

codespeed/tests/test_views.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,24 @@ def test_gettimelinedata(self):
341341
"base": "2+4",
342342
"ben": "float",
343343
"env": "1",
344-
"revs": 2
344+
"revs": "2"
345345
}
346346
response = self.client.get(path, data)
347347
self.assertEquals(response.status_code, 200)
348348
responsedata = json.loads(response.content.decode())
349+
349350
self.assertEquals(
350351
responsedata['error'], "None", "there should be no errors")
351352
self.assertEquals(
352353
len(responsedata['timelines']), 1, "there should be 1 benchmark")
353354
self.assertEquals(
354-
len(responsedata['timelines'][0]['branches']['master']),
355+
len(responsedata['timelines'][0]['branches']),
355356
2,
356-
"there should be 2 timelines")
357+
"there should be 2 branches")
358+
self.assertEquals(
359+
len(responsedata['timelines'][0]['branches']['default']),
360+
1,
361+
"there should be 1 timeline for master")
357362
self.assertEquals(
358363
len(responsedata['timelines'][0]['branches']['master']['1']),
359364
2,

codespeed/views.py

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,18 @@ def gettimelinedata(request):
231231

232232
timeline_list = {'error': 'None', 'timelines': []}
233233

234-
executables = data.get('exe', "").split(",")
235-
if not filter(None, executables):
234+
executable_ids = data.get('exe', '').split(',')
235+
236+
executables = []
237+
for i in executable_ids:
238+
if not i:
239+
continue
240+
try:
241+
executables.append(Executable.objects.get(id=int(i)))
242+
except Executable.DoesNotExist:
243+
pass
244+
245+
if not executables:
236246
timeline_list['error'] = "No executables selected"
237247
return HttpResponse(json.dumps(timeline_list))
238248
environment = None
@@ -270,22 +280,19 @@ def gettimelinedata(request):
270280
'branches': {},
271281
'baseline': "None",
272282
}
273-
# Temporary
274-
trunks = []
283+
append = False
275284
for proj in Project.objects.filter(track=True):
276285
try:
277-
default_branch = Branch.objects.get(
286+
branch = Branch.objects.get(
278287
project=proj, name=proj.default_branch)
279288
except Branch.DoesNotExist:
280289
continue
281-
else:
282-
trunks.append(default_branch)
283-
# For now, we'll only work with trunk branches
284-
append = False
285-
for branch in trunks:
286-
append = False
287-
timeline['branches'][branch.name] = {}
290+
291+
# For now, we'll only work with trunk branches
288292
for executable in executables:
293+
if executable.project != proj:
294+
continue
295+
289296
resultquery = Result.objects.filter(
290297
benchmark=bench
291298
).filter(
@@ -299,6 +306,7 @@ def gettimelinedata(request):
299306
).order_by('-revision__date')[:number_of_revs]
300307
if not len(resultquery):
301308
continue
309+
timeline['branches'].setdefault(branch.name, {})
302310

303311
results = []
304312
for res in resultquery:
@@ -333,32 +341,34 @@ def gettimelinedata(request):
333341
res.revision.get_short_commitid(), res.revision.tag, branch.name
334342
]
335343
)
336-
timeline['branches'][branch.name][executable] = results
344+
timeline['branches'][branch.name][executable.id] = results
337345
append = True
338346

339-
if baselinerev is not None and append:
340-
try:
341-
baselinevalue = Result.objects.get(
342-
executable=baselineexe,
343-
benchmark=bench,
344-
revision=baselinerev,
345-
environment=environment
346-
).value
347-
except Result.DoesNotExist:
348-
timeline['baseline'] = "None"
349-
else:
350-
# determine start and end revision (x axis)
351-
# from longest data series
352-
results = []
353-
for exe in timeline['branches'][branch.name]:
354-
if len(timeline['branches'][branch.name][exe]) > len(results):
355-
results = timeline['branches'][branch.name][exe]
356-
end = results[0][0]
357-
start = results[len(results) - 1][0]
358-
timeline['baseline'] = [
359-
[str(start), baselinevalue],
360-
[str(end), baselinevalue]
361-
]
347+
if baselinerev is not None and append:
348+
try:
349+
baselinevalue = Result.objects.get(
350+
executable=baselineexe,
351+
benchmark=bench,
352+
revision=baselinerev,
353+
environment=environment
354+
).value
355+
except Result.DoesNotExist:
356+
timeline['baseline'] = "None"
357+
else:
358+
# determine start and end revision (x axis)
359+
# from longest data series
360+
results = []
361+
for branch in timeline['branches']:
362+
for exe in timeline['branches'][branch]:
363+
if len(timeline['branches'][branch][exe]) > len(results):
364+
results = timeline['branches'][branch][exe]
365+
end = results[0][0]
366+
start = results[len(results) - 1][0]
367+
timeline['baseline'] = [
368+
[str(start), baselinevalue],
369+
[str(end), baselinevalue]
370+
]
371+
362372
if append:
363373
timeline_list['timelines'].append(timeline)
364374

0 commit comments

Comments
 (0)