Skip to content

Commit 2fc727c

Browse files
committed
Merge branch 'add_api' of https://github.com/a8/codespeed-a8 into a8-add_api
2 parents 7236c4f + d04149e commit 2fc727c

22 files changed

Lines changed: 1061 additions & 312 deletions

codespeed/api.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454

5555

5656
class UserResource(ModelResource):
57-
"""Ressource for Django User()"""
57+
"""Resource for Django User()"""
58+
5859
class Meta:
5960
queryset = User.objects.filter(is_active=True)
6061
resource_name = 'user'
@@ -68,31 +69,37 @@ class Meta:
6869

6970

7071
class ProjectResource(ModelResource):
71-
"""Ressource for Project()"""
72+
"""Resource for Project()"""
7273

7374
class Meta:
7475
queryset = Project.objects.all()
7576
authorization= Authorization()
7677

7778

7879
class BranchResource(ModelResource):
79-
"""Ressource for Branch()"""
80+
"""Resource for Branch()"""
81+
82+
project = fields.ToOneField(ProjectResource, 'project')
8083

8184
class Meta:
8285
queryset = Branch.objects.all()
8386
authorization= Authorization()
8487

8588

8689
class RevisionResource(ModelResource):
87-
"""Ressource for Revision()"""
90+
"""Resource for Revision()"""
91+
92+
project = fields.ToOneField(ProjectResource, 'project')
93+
branch = fields.ToOneField(BranchResource, 'branch')
8894

8995
class Meta:
9096
queryset = Revision.objects.all()
9197
authorization= Authorization()
9298

9399

94100
class ExecutableResource(ModelResource):
95-
"""Ressource for Executable()"""
101+
"""Resource for Executable()"""
102+
96103
project = fields.ToOneField(ProjectResource, 'project')
97104

98105
class Meta:
@@ -101,15 +108,15 @@ class Meta:
101108

102109

103110
class BenchmarkResource(ModelResource):
104-
"""Ressource for Benchmark()"""
111+
"""Resource for Benchmark()"""
105112

106113
class Meta:
107114
queryset = Benchmark.objects.all()
108115
authorization= Authorization()
109116

110117

111118
class EnvironmentResource(ModelResource):
112-
"""Ressource for Enviroment()"""
119+
"""Resource for Enviroment()"""
113120

114121
class Meta:
115122
queryset = Environment.objects.all()
@@ -118,18 +125,23 @@ class Meta:
118125

119126

120127
class ResultResource(ModelResource):
121-
"""Ressource for Result()"""
128+
"""Resource for Result()"""
122129

123130
class Meta:
124131
queryset = Result.objects.all()
125132
authorization= Authorization()
126133

127134

128135
class ReportResource(ModelResource):
129-
"""Ressource for Report()"""
136+
"""Resource for Report()"""
137+
138+
revision = fields.ToOneField(RevisionResource, 'revision')
139+
environment = fields.ToOneField(EnvironmentResource, 'environment')
140+
executable = fields.ToOneField(ExecutableResource, 'executable')
130141

131142
class Meta:
132143
queryset = Report.objects.all()
144+
allowed_methods = ['get']
133145
authorization= Authorization()
134146

135147

@@ -292,7 +304,7 @@ def _check_data(self):
292304
))
293305
# check optional data
294306
for key in [k for k in self.optional_keys \
295-
if k not in ('date')]:
307+
if k not in ('date',)]:
296308
if key in self.data.keys():
297309
try:
298310
self.data[key] = float(self.data[key])
@@ -325,7 +337,7 @@ def save(self):
325337

326338

327339
class ResultBundleResource(Resource):
328-
"""Ressource for all the data of a benchmark result.
340+
"""Resource for all the data of a benchmark result.
329341
330342
Primarily used to submit benchmark results
331343

codespeed/git.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010

1111

1212
def updaterepo(project, update=True):
13-
repo_name = os.path.splitext(project.repo_path.split(os.sep)[-1])[0]
14-
working_copy = os.path.join(settings.REPOSITORY_BASE_PATH, repo_name)
15-
16-
if os.path.exists(working_copy):
13+
if os.path.exists(project.working_copy):
1714
if not update:
1815
return
1916

2017
p = Popen(['git', 'pull'], stdout=PIPE, stderr=PIPE,
21-
cwd=working_copy)
18+
cwd=project.working_copy)
2219

2320
stdout, stderr = p.communicate()
2421
if p.returncode != 0:
@@ -27,7 +24,7 @@ def updaterepo(project, update=True):
2724
else:
2825
return [{'error': False}]
2926
else:
30-
cmd = ['git', 'clone', project.repo_path, repo_name]
27+
cmd = ['git', 'clone', project.repo_path, project.repo_name]
3128
p = Popen(cmd, stdout=PIPE, stderr=PIPE,
3229
cwd=settings.REPOSITORY_BASE_PATH)
3330
logger.debug('Cloning Git repo {0} for project {1}'.format(
@@ -43,11 +40,6 @@ def updaterepo(project, update=True):
4340
def getlogs(endrev, startrev):
4441
updaterepo(endrev.branch.project, update=False)
4542

46-
# TODO: Move all of this onto the model so we can avoid needing to repeat it:
47-
repo_name = os.path.splitext(
48-
endrev.branch.project.repo_path.split(os.sep)[-1])[0]
49-
working_copy = os.path.join(settings.REPOSITORY_BASE_PATH, repo_name)
50-
5143
cmd = ["git", "log",
5244
# NULL separated values delimited by 0x1e record separators
5345
# See PRETTY FORMATS in git-log(1):
@@ -59,6 +51,7 @@ def getlogs(endrev, startrev):
5951
cmd.append("-1") # Only return one commit
6052
cmd.append(endrev.commitid)
6153

54+
working_copy = endrev.branch.project.working_copy
6255
p = Popen(cmd, stdout=PIPE, stderr=PIPE, cwd=working_copy)
6356

6457
stdout, stderr = p.communicate()

codespeed/github.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def retrieve_revision(commit_id, username, project, revision = None):
7878
'author_email': commit['author']['email'],
7979
'commitid': commit['id'],
8080
'short_commit_id': commit['id'][0:7],
81-
'links': {'Github': 'http://github.com%s' % commit['url']},
8281
'parents': commit['parents']}
8382

8483
def getlogs(endrev, startrev):

codespeed/mercurial.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99

1010

1111
def updaterepo(project, update=True):
12-
repo_name = os.path.splitext(project.repo_path.split(os.sep)[-1])[0]
13-
working_copy = os.path.join(settings.REPOSITORY_BASE_PATH, repo_name)
14-
15-
if os.path.exists(working_copy):
12+
if os.path.exists(project.working_copy):
1613
if not update:
1714
return
1815

1916
p = Popen(['hg', 'pull', '-u'], stdout=PIPE, stderr=PIPE,
20-
cwd=working_copy)
17+
cwd=project.working_copy)
2118
stdout, stderr = p.communicate()
2219

2320
if p.returncode != 0 or stderr:
@@ -27,7 +24,7 @@ def updaterepo(project, update=True):
2724
return [{'error': False}]
2825
else:
2926
# Clone repo
30-
cmd = ['hg', 'clone', project.repo_path, repo_name]
27+
cmd = ['hg', 'clone', project.repo_path, project.repo_name]
3128

3229
p = Popen(cmd, stdout=PIPE, stderr=PIPE,
3330
cwd=settings.REPOSITORY_BASE_PATH)
@@ -45,15 +42,12 @@ def updaterepo(project, update=True):
4542
def getlogs(endrev, startrev):
4643
updaterepo(endrev.branch.project, update=False)
4744

48-
# TODO: Move all of this onto the model so we can avoid needing to repeat it:
49-
repo_name = os.path.splitext(endrev.branch.project.repo_path.split(os.sep)[-1])[0]
50-
working_copy = os.path.join(settings.REPOSITORY_BASE_PATH, repo_name)
51-
5245
cmd = ["hg", "log",
5346
"-r", "%s:%s" % (endrev.commitid, startrev.commitid),
5447
"-b", "default",
5548
"--template", "{rev}:{node|short}\n{node}\n{author|user}\n{author|email}\n{date}\n{desc}\n=newlog=\n"]
5649

50+
working_copy = endrev.branch.project.working_copy
5751
p = Popen(cmd, stdout=PIPE, stderr=PIPE, cwd=working_copy)
5852
stdout, stderr = p.communicate()
5953

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# encoding: utf-8
2+
import datetime
3+
from south.db import db
4+
from south.v2 import SchemaMigration
5+
from django.db import models
6+
7+
class Migration(SchemaMigration):
8+
9+
def forwards(self, orm):
10+
11+
# Adding field 'Project.commit_browsing_url'
12+
db.add_column('codespeed_project', 'commit_browsing_url', self.gf('django.db.models.fields.CharField')(default='', max_length=200, blank=True), keep_default=False)
13+
14+
15+
def backwards(self, orm):
16+
17+
# Deleting field 'Project.commit_browsing_url'
18+
db.delete_column('codespeed_project', 'commit_browsing_url')
19+
20+
21+
models = {
22+
'codespeed.benchmark': {
23+
'Meta': {'object_name': 'Benchmark'},
24+
'benchmark_type': ('django.db.models.fields.CharField', [], {'default': "'C'", 'max_length': '1'}),
25+
'default_on_comparison': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
26+
'description': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}),
27+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
28+
'lessisbetter': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
29+
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
30+
'units': ('django.db.models.fields.CharField', [], {'default': "'seconds'", 'max_length': '20'}),
31+
'units_title': ('django.db.models.fields.CharField', [], {'default': "'Time'", 'max_length': '30'})
32+
},
33+
'codespeed.branch': {
34+
'Meta': {'unique_together': "(('name', 'project'),)", 'object_name': 'Branch'},
35+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
36+
'name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
37+
'project': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'branches'", 'to': "orm['codespeed.Project']"})
38+
},
39+
'codespeed.environment': {
40+
'Meta': {'object_name': 'Environment'},
41+
'cpu': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
42+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
43+
'kernel': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
44+
'memory': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
45+
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
46+
'os': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'})
47+
},
48+
'codespeed.executable': {
49+
'Meta': {'object_name': 'Executable'},
50+
'description': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
51+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
52+
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
53+
'project': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'executables'", 'to': "orm['codespeed.Project']"})
54+
},
55+
'codespeed.project': {
56+
'Meta': {'object_name': 'Project'},
57+
'commit_browsing_url': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
58+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
59+
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
60+
'repo_pass': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
61+
'repo_path': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
62+
'repo_type': ('django.db.models.fields.CharField', [], {'default': "'N'", 'max_length': '1'}),
63+
'repo_user': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
64+
'track': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
65+
},
66+
'codespeed.report': {
67+
'Meta': {'unique_together': "(('revision', 'executable', 'environment'),)", 'object_name': 'Report'},
68+
'_tablecache': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
69+
'colorcode': ('django.db.models.fields.CharField', [], {'default': "'none'", 'max_length': '10'}),
70+
'environment': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'reports'", 'to': "orm['codespeed.Environment']"}),
71+
'executable': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'reports'", 'to': "orm['codespeed.Executable']"}),
72+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
73+
'revision': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'reports'", 'to': "orm['codespeed.Revision']"}),
74+
'summary': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'})
75+
},
76+
'codespeed.result': {
77+
'Meta': {'unique_together': "(('revision', 'executable', 'benchmark', 'environment'),)", 'object_name': 'Result'},
78+
'benchmark': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'results'", 'to': "orm['codespeed.Benchmark']"}),
79+
'date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
80+
'environment': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'results'", 'to': "orm['codespeed.Environment']"}),
81+
'executable': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'results'", 'to': "orm['codespeed.Executable']"}),
82+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
83+
'revision': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'results'", 'to': "orm['codespeed.Revision']"}),
84+
'std_dev': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
85+
'val_max': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
86+
'val_min': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
87+
'value': ('django.db.models.fields.FloatField', [], {})
88+
},
89+
'codespeed.revision': {
90+
'Meta': {'unique_together': "(('commitid', 'branch'),)", 'object_name': 'Revision'},
91+
'author': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
92+
'branch': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'revisions'", 'to': "orm['codespeed.Branch']"}),
93+
'commitid': ('django.db.models.fields.CharField', [], {'max_length': '42'}),
94+
'date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
95+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
96+
'message': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
97+
'project': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'revisions'", 'null': 'True', 'to': "orm['codespeed.Project']"}),
98+
'tag': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'})
99+
}
100+
}
101+
102+
complete_apps = ['codespeed']

0 commit comments

Comments
 (0)