Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gabriel Silva Vinha
codespeed
Commits
47b6477a
Commit
47b6477a
authored
Aug 06, 2017
by
Miquel Torres
Browse files
Adjust gettimelines to work properly with default_branch
parent
b4a8882a
Changes
3
Hide whitespace changes
Inline
Side-by-side
codespeed/fixtures/timeline_tests.json
View file @
47b6477a
...
...
@@ -37,7 +37,8 @@
"repo_user"
:
""
,
"track"
:
false
,
"repo_pass"
:
""
,
"repo_path"
:
""
"repo_path"
:
""
,
"default_branch"
:
"master"
}
},
{
...
...
@@ -61,7 +62,7 @@
"model"
:
"codespeed.branch"
,
"fields"
:
{
"project"
:
2
,
"name"
:
"
master
"
"name"
:
"
default
"
}
},
{
...
...
codespeed/tests/test_views.py
View file @
47b6477a
...
...
@@ -341,19 +341,24 @@ class TestTimeline(TestCase):
"base"
:
"2+4"
,
"ben"
:
"float"
,
"env"
:
"1"
,
"revs"
:
2
"revs"
:
"2"
}
response
=
self
.
client
.
get
(
path
,
data
)
self
.
assertEquals
(
response
.
status_code
,
200
)
responsedata
=
json
.
loads
(
response
.
content
.
decode
())
self
.
assertEquals
(
responsedata
[
'error'
],
"None"
,
"there should be no errors"
)
self
.
assertEquals
(
len
(
responsedata
[
'timelines'
]),
1
,
"there should be 1 benchmark"
)
self
.
assertEquals
(
len
(
responsedata
[
'timelines'
][
0
][
'branches'
]
[
'master'
]
),
len
(
responsedata
[
'timelines'
][
0
][
'branches'
]),
2
,
"there should be 2 timelines"
)
"there should be 2 branches"
)
self
.
assertEquals
(
len
(
responsedata
[
'timelines'
][
0
][
'branches'
][
'default'
]),
1
,
"there should be 1 timeline for master"
)
self
.
assertEquals
(
len
(
responsedata
[
'timelines'
][
0
][
'branches'
][
'master'
][
'1'
]),
2
,
...
...
codespeed/views.py
View file @
47b6477a
...
...
@@ -231,8 +231,18 @@ def gettimelinedata(request):
timeline_list
=
{
'error'
:
'None'
,
'timelines'
:
[]}
executables
=
data
.
get
(
'exe'
,
""
).
split
(
","
)
if
not
filter
(
None
,
executables
):
executable_ids
=
data
.
get
(
'exe'
,
''
).
split
(
','
)
executables
=
[]
for
i
in
executable_ids
:
if
not
i
:
continue
try
:
executables
.
append
(
Executable
.
objects
.
get
(
id
=
int
(
i
)))
except
Executable
.
DoesNotExist
:
pass
if
not
executables
:
timeline_list
[
'error'
]
=
"No executables selected"
return
HttpResponse
(
json
.
dumps
(
timeline_list
))
environment
=
None
...
...
@@ -270,22 +280,19 @@ def gettimelinedata(request):
'branches'
:
{},
'baseline'
:
"None"
,
}
# Temporary
trunks
=
[]
append
=
False
for
proj
in
Project
.
objects
.
filter
(
track
=
True
):
try
:
default_
branch
=
Branch
.
objects
.
get
(
branch
=
Branch
.
objects
.
get
(
project
=
proj
,
name
=
proj
.
default_branch
)
except
Branch
.
DoesNotExist
:
continue
else
:
trunks
.
append
(
default_branch
)
# For now, we'll only work with trunk branches
append
=
False
for
branch
in
trunks
:
append
=
False
timeline
[
'branches'
][
branch
.
name
]
=
{}
# For now, we'll only work with trunk branches
for
executable
in
executables
:
if
executable
.
project
!=
proj
:
continue
resultquery
=
Result
.
objects
.
filter
(
benchmark
=
bench
).
filter
(
...
...
@@ -299,6 +306,7 @@ def gettimelinedata(request):
).
order_by
(
'-revision__date'
)[:
number_of_revs
]
if
not
len
(
resultquery
):
continue
timeline
[
'branches'
].
setdefault
(
branch
.
name
,
{})
results
=
[]
for
res
in
resultquery
:
...
...
@@ -333,32 +341,34 @@ def gettimelinedata(request):
res
.
revision
.
get_short_commitid
(),
res
.
revision
.
tag
,
branch
.
name
]
)
timeline
[
'branches'
][
branch
.
name
][
executable
]
=
results
timeline
[
'branches'
][
branch
.
name
][
executable
.
id
]
=
results
append
=
True
if
baselinerev
is
not
None
and
append
:
try
:
baselinevalue
=
Result
.
objects
.
get
(
executable
=
baselineexe
,
benchmark
=
bench
,
revision
=
baselinerev
,
environment
=
environment
).
value
except
Result
.
DoesNotExist
:
timeline
[
'baseline'
]
=
"None"
else
:
# determine start and end revision (x axis)
# from longest data series
results
=
[]
for
exe
in
timeline
[
'branches'
][
branch
.
name
]:
if
len
(
timeline
[
'branches'
][
branch
.
name
][
exe
])
>
len
(
results
):
results
=
timeline
[
'branches'
][
branch
.
name
][
exe
]
end
=
results
[
0
][
0
]
start
=
results
[
len
(
results
)
-
1
][
0
]
timeline
[
'baseline'
]
=
[
[
str
(
start
),
baselinevalue
],
[
str
(
end
),
baselinevalue
]
]
if
baselinerev
is
not
None
and
append
:
try
:
baselinevalue
=
Result
.
objects
.
get
(
executable
=
baselineexe
,
benchmark
=
bench
,
revision
=
baselinerev
,
environment
=
environment
).
value
except
Result
.
DoesNotExist
:
timeline
[
'baseline'
]
=
"None"
else
:
# determine start and end revision (x axis)
# from longest data series
results
=
[]
for
branch
in
timeline
[
'branches'
]:
for
exe
in
timeline
[
'branches'
][
branch
]:
if
len
(
timeline
[
'branches'
][
branch
][
exe
])
>
len
(
results
):
results
=
timeline
[
'branches'
][
branch
][
exe
]
end
=
results
[
0
][
0
]
start
=
results
[
len
(
results
)
-
1
][
0
]
timeline
[
'baseline'
]
=
[
[
str
(
start
),
baselinevalue
],
[
str
(
end
),
baselinevalue
]
]
if
append
:
timeline_list
[
'timelines'
].
append
(
timeline
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment