Skip to content

Commit 37b023b

Browse files
committed
Set default_branch based on repo type
1 parent 69fab17 commit 37b023b

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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):

0 commit comments

Comments
 (0)