Skip to content

Commit a577496

Browse files
authored
Merge pull request #224 from tobami/default-banch-in-db
Default banch in db
2 parents 69f7405 + 3743ece commit a577496

File tree

12 files changed

+159
-78
lines changed

12 files changed

+159
-78
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ several parameters (the file includes comments with full examples).
185185
* `grid`: will always show as default the grid of plots
186186
* `show_none`: will show a text message (better default when there are lots of benchmarks)
187187
* `mybench`: will select benchmark named "mybench"
188-
* `DEF_BRANCH`: Defines the default branch to be used when calculating timeline and changes data for presentation. Example values:
189-
* `default`: the default value, and usually mercurial's default branch
190-
* `master`: usually git's default branch
191-
* `trunk`: usually SVN's default branch
192188

193189
### Comparison View
194190
* `CHART_TYPE`: Chooses the default chart type (normal bars, stacked bars or

codespeed/admin.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
# -*- coding: utf-8 -*-
22

3+
from django import forms
4+
from django.contrib import admin
5+
36
from codespeed.models import (Project, Revision, Executable, Benchmark, Branch,
47
Result, Environment, Report)
58

6-
from django.contrib import admin
9+
10+
class ProjectForm(forms.ModelForm):
11+
12+
default_branch = forms.CharField(max_length=32, required=False)
13+
14+
def clean(self):
15+
if not self.cleaned_data.get('default_branch'):
16+
repo_type = self.cleaned_data['repo_type']
17+
if repo_type in [Project.GIT, Project.GITHUB]:
18+
self.cleaned_data['default_branch'] = "master"
19+
elif repo_type == Project.MERCURIAL:
20+
self.cleaned_data['default_branch'] = "default"
21+
elif repo_type == Project.SUBVERSION:
22+
self.cleaned_data['default_branch'] = "trunk"
23+
else:
24+
self.add_error('default_branch', 'This field is required.')
25+
26+
class Meta:
27+
model = Project
28+
fields = '__all__'
729

830

931
@admin.register(Project)
1032
class ProjectAdmin(admin.ModelAdmin):
1133
list_display = ('name', 'repo_type', 'repo_path', 'track')
1234

35+
form = ProjectForm
36+
1337

1438
@admin.register(Branch)
1539
class BranchAdmin(admin.ModelAdmin):

codespeed/feeds.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ def get_context_data(self, **kwargs):
3535

3636

3737
class LatestEntries(ResultFeed):
38-
description = "Last benchmark runs"
38+
description = "Last Results"
3939

4040
def result_filter(self):
41-
return Q(revision__branch__name=settings.DEF_BRANCH)
41+
return Q()
4242

4343

4444
class LatestSignificantEntries(ResultFeed):
45-
description = "Last benchmark runs with significant changes"
45+
description = "Last results with significant changes"
4646

4747
def result_filter(self):
48-
return Q(revision__branch__name=settings.DEF_BRANCH,
49-
colorcode__in=('red', 'green'))
48+
return Q(colorcode__in=('red', 'green'))

codespeed/fixtures/timeline_tests.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@
33
"pk": 1,
44
"model": "codespeed.project",
55
"fields": {
6-
"repo_type": "N",
6+
"repo_type": "G",
77
"name": "MyProject",
88
"commit_browsing_url": "",
99
"repo_user": "",
1010
"track": true,
1111
"repo_pass": "",
12-
"repo_path": ""
12+
"repo_path": "",
13+
"default_branch": "master"
1314
}
1415
},
1516
{
1617
"pk": 2,
1718
"model": "codespeed.project",
1819
"fields": {
19-
"repo_type": "N",
20+
"repo_type": "M",
2021
"name": "Other",
2122
"commit_browsing_url": "",
2223
"repo_user": "",
2324
"track": true,
2425
"repo_pass": "",
25-
"repo_path": ""
26+
"repo_path": "",
27+
"default_branch": "default"
2628
}
2729
},
2830
{
@@ -35,7 +37,8 @@
3537
"repo_user": "",
3638
"track": false,
3739
"repo_pass": "",
38-
"repo_path": ""
40+
"repo_path": "",
41+
"default_branch": "master"
3942
}
4043
},
4144
{
@@ -59,7 +62,7 @@
5962
"model": "codespeed.branch",
6063
"fields": {
6164
"project": 2,
62-
"name": "master"
65+
"name": "default"
6366
}
6467
},
6568
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.13 on 2017-08-04 03:45
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
def get_default_branch_name():
9+
from django.conf import settings
10+
try:
11+
return settings.DEF_BRANCH
12+
except AttributeError:
13+
return "master"
14+
15+
16+
class Migration(migrations.Migration):
17+
18+
dependencies = [
19+
('codespeed', '0002_median'),
20+
]
21+
22+
operations = [
23+
migrations.AddField(
24+
model_name='project',
25+
name='default_branch',
26+
field=models.CharField(default=get_default_branch_name, max_length=32),
27+
preserve_default=False,
28+
),
29+
migrations.AlterField(
30+
model_name='branch',
31+
name='name',
32+
field=models.CharField(max_length=32),
33+
),
34+
]

codespeed/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Project(models.Model):
4242
commit_browsing_url = models.CharField("Commit browsing URL",
4343
blank=True, max_length=200)
4444
track = models.BooleanField("Track changes", default=True)
45+
default_branch = models.CharField(max_length=32)
4546

4647
def __str__(self):
4748
return self.name
@@ -103,7 +104,7 @@ def is_less_important_than(self, val, color):
103104

104105
@python_2_unicode_compatible
105106
class Branch(models.Model):
106-
name = models.CharField(max_length=20)
107+
name = models.CharField(max_length=32)
107108
project = models.ForeignKey(Project, related_name="branches")
108109

109110
def __str__(self):
@@ -138,7 +139,7 @@ def __str__(self):
138139
else:
139140
date = self.date.strftime("%b %d, %H:%M")
140141
string = " - ".join(filter(None, (date, self.commitid, self.tag)))
141-
if self.branch.name != settings.DEF_BRANCH:
142+
if self.branch.name != self.branch.project.default_branch:
142143
string += " - " + self.branch.name
143144
return string
144145

codespeed/results.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def save_result(data):
134134

135135
def create_report_if_enough_data(rev, exe, e):
136136
"""Triggers Report creation when there are enough results"""
137+
if exe.project.track is not True:
138+
return False
139+
137140
last_revs = Revision.objects.filter(
138141
branch=rev.branch
139142
).order_by('-date')[:2]

codespeed/settings.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
DEF_ENVIRONMENT = None # Name of the environment which should be selected as default
88

9-
DEF_BRANCH = "master" # Defines the default branch to be used.
10-
# In git projects, this branch is usually called "master"
11-
129
DEF_BASELINE = None # Which executable + revision should be default as a baseline
1310
# Given as the name of the executable and commitid of the revision
1411
# Example: defaultbaseline = {'executable': 'myexe', 'revision': '21'}

codespeed/tests/test_views.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import copy
44
import json
55

6-
from django.conf import settings
76
from django.test import TestCase, override_settings
87
from django.core.urlresolvers import reverse
98

@@ -342,19 +341,24 @@ def test_gettimelinedata(self):
342341
"base": "2+4",
343342
"ben": "float",
344343
"env": "1",
345-
"revs": 2
344+
"revs": "2"
346345
}
347346
response = self.client.get(path, data)
348347
self.assertEquals(response.status_code, 200)
349348
responsedata = json.loads(response.content.decode())
349+
350350
self.assertEquals(
351351
responsedata['error'], "None", "there should be no errors")
352352
self.assertEquals(
353353
len(responsedata['timelines']), 1, "there should be 1 benchmark")
354354
self.assertEquals(
355-
len(responsedata['timelines'][0]['branches']['master']),
355+
len(responsedata['timelines'][0]['branches']),
356356
2,
357-
"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")
358362
self.assertEquals(
359363
len(responsedata['timelines'][0]['branches']['master']['1']),
360364
2,
@@ -371,7 +375,7 @@ def setUp(self):
371375
Environment.objects.create(name='Dual Core', cpu='Core 2 Duo 8200')
372376
self.data = {
373377
'commitid': 'abcd1',
374-
'branch': settings.DEF_BRANCH,
378+
'branch': 'master',
375379
'project': 'MyProject',
376380
'executable': 'myexe O3 64bits',
377381
'benchmark': 'float',
@@ -399,3 +403,13 @@ def test_reports_post_returns_405(self):
399403
response = self.client.post(reverse('codespeed.views.reports'), {})
400404

401405
self.assertEqual(response.status_code, 405)
406+
407+
408+
class TestFeeds(TestCase):
409+
410+
def test_latest_result_feed(self):
411+
response = self.client.get(reverse('latest-results'))
412+
413+
self.assertEqual(response.status_code, 200)
414+
content = response.content.decode()
415+
self.assertIn('<atom:link ', content)

codespeed/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'),
1010
url(r'^about/$', TemplateView.as_view(template_name='about.html'), name='about'),
1111
# RSS for reports
12-
url(r'^feeds/latest/$', LatestEntries(), name='latest_feeds'),
12+
url(r'^feeds/latest/$', LatestEntries(), name='latest-results'),
1313
url(r'^feeds/latest_significant/$', LatestSignificantEntries(),
14-
name='latest_significant_feeds'),
14+
name='latest-significant-results'),
1515
)
1616

1717
urlpatterns += patterns('codespeed.views',

0 commit comments

Comments
 (0)