Skip to content

Commit f0910ff

Browse files
authored
Merge pull request tobami#283 from Kami/configurable_comparison_display_branch
Allow admin to configure which branches are displayed on the Comparison page
2 parents 7450893 + 001388d commit f0910ff

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

codespeed/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ProjectAdmin(admin.ModelAdmin):
3737

3838
@admin.register(Branch)
3939
class BranchAdmin(admin.ModelAdmin):
40-
list_display = ('name', 'project')
40+
list_display = ('name', 'project', 'display_on_comparison_page')
4141
list_filter = ('project',)
4242

4343

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.1.15 on 2020-02-24 11:26
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('codespeed', '0003_project_default_branch'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='branch',
15+
name='display_on_comparison_page',
16+
field=models.BooleanField(default=True, verbose_name='True to display this branch on the comparison page'),
17+
),
18+
]

codespeed/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class Branch(models.Model):
107107
name = models.CharField(max_length=32)
108108
project = models.ForeignKey(
109109
Project, on_delete=models.CASCADE, related_name="branches")
110+
display_on_comparison_page = models.BooleanField(
111+
"True to display this branch on the comparison page",
112+
default=True)
110113

111114
def __str__(self):
112115
return self.project.name + ":" + self.name

codespeed/tests/test_views_data.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,38 @@ def test_get_comparisionexes_custom_default_branch(self):
141141
self.assertEqual(exe_keys[2], '1+L+custom')
142142
self.assertEqual(exe_keys[3], '2+L+custom')
143143

144+
def test_get_comparisionexes_branch_filtering(self):
145+
# branch1 and branch3 have display_on_comparison_page flag set to False
146+
# so they shouldn't be included in the result
147+
branch1 = Branch.objects.create(name='branch1', project=self.project,
148+
display_on_comparison_page=False)
149+
branch2 = Branch.objects.create(name='branch2', project=self.project,
150+
display_on_comparison_page=True)
151+
branch3 = Branch.objects.create(name='branch3', project=self.project,
152+
display_on_comparison_page=False)
153+
154+
Revision.objects.create(branch=branch1, commitid='1')
155+
Revision.objects.create(branch=branch2, commitid='1')
156+
Revision.objects.create(branch=branch3, commitid='1')
157+
158+
executables, exe_keys = getcomparisonexes()
159+
self.assertEqual(len(executables), 1)
160+
self.assertEqual(len(executables[self.project]), 6)
161+
self.assertEqual(len(exe_keys), 6)
162+
163+
expected_exe_keys = [
164+
'1+L+master',
165+
'2+L+master',
166+
'1+L+custom',
167+
'2+L+custom',
168+
'1+L+branch2',
169+
'2+L+branch2'
170+
]
171+
self.assertEqual(exe_keys, expected_exe_keys)
172+
173+
for index, exe_key in enumerate(expected_exe_keys):
174+
self.assertEqual(executables[self.project][index]['key'], exe_key)
175+
144176

145177
class UtilityFunctionsTestCase(TestCase):
146178
@override_settings(TIMELINE_EXECUTABLE_NAME_MAX_LEN=22)

codespeed/views_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def getcomparisonexes():
120120
executables.append(exe)
121121

122122
# add latest revs of the project
123-
branches = Branch.objects.filter(project=proj)
123+
branches = Branch.objects.filter(project=proj, display_on_comparison_page=True)
124124
for branch in branches:
125125
try:
126126
rev = Revision.objects.filter(branch=branch).latest('date')

0 commit comments

Comments
 (0)