Skip to content

Commit f33429c

Browse files
committed
Allow user to specify which tags to include in the comparision page
executables list. This comes handy in scenarios where there are a lot of tags, but you only want to list / include some of them. NOTE: For backward compatibility reasons, default value is None which means include all the tags.
1 parent f0910ff commit f33429c

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

codespeed/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
# ('myexe', '21df2423ra'),
7979
# ('myexe', 'L'),]
8080

81+
COMPARISON_TAGS = None # List of tag names which should be included on the comparision page.
82+
# If this value is set to None, all the available tags will be included.
83+
# Empty list means no tags will be included.
84+
8185
TIMELINE_EXECUTABLE_NAME_MAX_LEN = 22 # Maximum length of the executable name used in the
8286
# Changes and Timeline view. If the name is longer, the name
8387
# will be truncated and "..." will be added at the end.

codespeed/tests/test_views_data.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,70 @@ def test_get_comparisionexes_branch_filtering(self):
173173
for index, exe_key in enumerate(expected_exe_keys):
174174
self.assertEqual(executables[self.project][index]['key'], exe_key)
175175

176+
def test_get_comparisionexes_tag_name_filtering(self):
177+
# Insert some mock revisions with tags
178+
rev_v4 = Revision.objects.create(
179+
branch=self.branch_master, commitid='4', tag='v4.0.0')
180+
rev_v5 = Revision.objects.create(
181+
branch=self.branch_master, commitid='5', tag='v5.0.0')
182+
rev_v6 = Revision.objects.create(
183+
branch=self.branch_master, commitid='6', tag='v6.0.0')
184+
185+
# No COMPARIION_TAGS filters specified, all the tags should be included
186+
executables, exe_keys = getcomparisonexes()
187+
self.assertEqual(len(executables), 1)
188+
self.assertEqual(len(executables[self.project]), 2 * 2 + 2 * 3)
189+
self.assertEqual(len(exe_keys), 2 * 2 + 2 * 3)
190+
191+
self.assertExecutablesListContainsRevision(executables[self.project], rev_v4)
192+
self.assertExecutablesListContainsRevision(executables[self.project], rev_v5)
193+
self.assertExecutablesListContainsRevision(executables[self.project], rev_v6)
194+
195+
# Only a single tag should be included
196+
with override_settings(COMPARISON_TAGS=['v4.0.0']):
197+
executables, exe_keys = getcomparisonexes()
198+
self.assertEqual(len(executables), 1)
199+
self.assertEqual(len(executables[self.project]), 2 * 2 + 2 * 1)
200+
self.assertEqual(len(exe_keys), 2 * 2 + 2 * 1)
201+
202+
self.assertExecutablesListContainsRevision(executables[self.project], rev_v4)
203+
self.assertExecutablesListDoesntContainRevision(executables[self.project], rev_v5)
204+
self.assertExecutablesListDoesntContainRevision(executables[self.project], rev_v6)
205+
206+
# No tags should be included
207+
with override_settings(COMPARISON_TAGS=[]):
208+
executables, exe_keys = getcomparisonexes()
209+
self.assertEqual(len(executables), 1)
210+
self.assertEqual(len(executables[self.project]), 2 * 2)
211+
self.assertEqual(len(exe_keys), 2 * 2)
212+
213+
self.assertExecutablesListDoesntContainRevision(executables[self.project], rev_v4)
214+
self.assertExecutablesListDoesntContainRevision(executables[self.project], rev_v5)
215+
self.assertExecutablesListDoesntContainRevision(executables[self.project], rev_v6)
216+
217+
def assertExecutablesListContainsRevision(self, executables, revision):
218+
found = self._executable_list_contains_revision(executables=executables,
219+
revision=revision)
220+
221+
if not found:
222+
self.assertFalse("Didn't find revision \"%s\" in executable list \"%s\"" %
223+
(str(revision), str(executables)))
224+
225+
def assertExecutablesListDoesntContainRevision(self, executables, revision):
226+
found = self._executable_list_contains_revision(executables=executables,
227+
revision=revision)
228+
229+
if found:
230+
self.assertFalse("Found revision \"%s\", but didn't expect it" %
231+
(str(revision)))
232+
233+
def _executable_list_contains_revision(self, executables, revision):
234+
for executable in executables:
235+
if executable['revision'] == revision:
236+
return True
237+
238+
return False
239+
176240

177241
class UtilityFunctionsTestCase(TestCase):
178242
@override_settings(TIMELINE_EXECUTABLE_NAME_MAX_LEN=22)

codespeed/views_data.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,27 @@ def get_default_environment(enviros, data, multi=False):
4949
return defaultenviros[0]
5050

5151

52-
def getbaselineexecutables():
52+
def getbaselineexecutables(include_tags=None):
53+
"""
54+
:param include_tags: A list of tags to include in the result. If not specified, it will
55+
include all the available tags.
56+
:type include_tags: ``list``
57+
"""
5358
baseline = [{
5459
'key': "none",
5560
'name': "None",
5661
'executable': "none",
5762
'revision': "none",
5863
}]
5964
executables = Executable.objects.select_related('project')
60-
revs = Revision.objects.exclude(tag="").select_related('branch__project')
65+
66+
if include_tags is not None:
67+
revs = Revision.objects.filter(tag__in=include_tags)
68+
else:
69+
revs = Revision.objects.exclude(tag="")
70+
71+
revs = revs.select_related('branch__project')
72+
6173
for rev in revs:
6274
# Add executables that correspond to each tagged revision.
6375
for exe in [e for e in executables if e.project == rev.branch.project]:
@@ -107,9 +119,12 @@ def getdefaultexecutable():
107119

108120

109121
def getcomparisonexes():
122+
comparison_tags = getattr(settings, 'COMPARISON_TAGS', None)
123+
110124
all_executables = {}
111125
exekeys = []
112-
baselines = getbaselineexecutables()
126+
baselines = getbaselineexecutables(include_tags=comparison_tags)
127+
113128
for proj in Project.objects.all():
114129
executables = []
115130
executablekeys = []

0 commit comments

Comments
 (0)