Download:
child 110:6b22a1b4b85c
parent 108:4fced0617745
109:6cbbab799f3c
Anton Shestakov <av6@dwimlabs.net>, Tue, 05 Jul 2016 20:48:01 +0800
viewer: provide change/branch links for projects (i.e. on Bitbucket)

6 файлов изменено, 43 вставок(+), 7 удалений(-) [+]
candolint/adapters.py file | annotate | diff | comparison | revisions
candolint/handlers.py file | annotate | diff | comparison | revisions
candolint/models.py file | annotate | diff | comparison | revisions
templates/check.html file | annotate | diff | comparison | revisions
templates/index.html file | annotate | diff | comparison | revisions
templates/project.html file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/candolint/adapters.py Tue Jul 05 20:48:01 2016 +0800
@@ -0,0 +1,23 @@
+class HostingAdapter(object):
+ def __init__(self, project):
+ self.project = project
+
+ def get_commit_url(self, change):
+ return ''
+
+ def get_branch_url(self, change):
+ return ''
+
+
+class BitbucketAdapter(HostingAdapter):
+ def get_commit_url(self, change):
+ return '{url}/commits/{node}'.format(**{
+ 'url': self.project.url,
+ 'node': change.node
+ })
+
+ def get_branch_url(self, change):
+ return '{url}/branch/{branch}'.format(**{
+ 'url': self.project.url,
+ 'branch': change.branch
+ })
--- a/candolint/handlers.py Tue Jul 05 20:44:04 2016 +0800
+++ b/candolint/handlers.py Tue Jul 05 20:48:01 2016 +0800
@@ -92,7 +92,8 @@
self.write('\n')
def get_html(self, project, check, lines):
- self.render('check.html', project=project, check=check, lines=lines)
+ adapter = project.get_adapter()
+ self.render('check.html', project=project, check=check, lines=lines, adapter=adapter)
class StatusHandler(BaseHandler):
--- a/candolint/models.py Tue Jul 05 20:44:04 2016 +0800
+++ b/candolint/models.py Tue Jul 05 20:48:01 2016 +0800
@@ -1,5 +1,9 @@
+from __future__ import absolute_import
+
import peewee as pw
+from candolint import adapters
+
database = pw.SqliteDatabase(None, journal_mode='WAL')
@@ -50,6 +54,12 @@
owner = self.user if self.user is not None else self.domain
return '{}/{}'.format(owner, self.name)
+ def get_adapter(self):
+ if self.domain == 'bitbucket.org':
+ return adapters.BitbucketAdapter(self)
+ else:
+ return adapters.HostingAdapter(self)
+
class Change(BaseModel):
rev = pw.IntegerField()
--- a/templates/check.html Tue Jul 05 20:44:04 2016 +0800
+++ b/templates/check.html Tue Jul 05 20:48:01 2016 +0800
@@ -33,9 +33,9 @@
<dl class="uk-description-list-horizontal list-terse">
{% set change = check.change %}
<dt>Commit:</dt>
- <dd>{{ change.rev }}:{{ change.node[:12] }}</dd>
+ <dd><a href="{{ adapter.get_commit_url(change) }}">{{ change.rev }}:{{ change.node[:12] }}</a></dd>
<dt>Branch:</dt>
- <dd>{{ change.branch }}</dd>
+ <dd><a href="{{ adapter.get_branch_url(change) }}">{{ change.branch }}</a></dd>
<dt>Author:</dt>
<dd>{{ change.author }}</dd>
<dt>Date:</dt>
--- a/templates/index.html Tue Jul 05 20:44:04 2016 +0800
+++ b/templates/index.html Tue Jul 05 20:48:01 2016 +0800
@@ -10,12 +10,13 @@
{% for check in checks %}
{% set project = check.project %}
{% set change = check.change %}
+ {% set adapter = project.get_adapter() %}
<tr>
<td>{% module Badges(check) %}</td>
<td><a href="{{ check.get_url() }}">check #{{ check.ordinal }}</a></td>
<td class="uk-width-1-1 uk-text-break"><a href="{{ project.get_url() }}">{{ project.get_title() }}</a></td>
- <td>{{ change.branch }}</td>
- <td>{{ change.rev }}:{{ change.node[:12] }}</td>
+ <td><a href="{{ adapter.get_branch_url(change) }}">{{ change.branch }}</a></td>
+ <td><a href="{{ adapter.get_commit_url(change) }}">{{ change.rev }}:{{ change.node[:12] }}</a></td>
<td>{% module Time(check.finished) %}</td>
<td>{{ check.get_duration() }}</td>
</tr>
--- a/templates/project.html Tue Jul 05 20:44:04 2016 +0800
+++ b/templates/project.html Tue Jul 05 20:48:01 2016 +0800
@@ -19,11 +19,12 @@
<tbody>
{% for check in checks %}
{% set change = check.change %}
+ {% set adapter = project.get_adapter() %}
<tr>
<td>{% module Badges(check) %}</td>
<td><a href="{{ check.get_url() }}">check #{{ check.ordinal }}</a></td>
- <td>{{ change.branch }}</td>
- <td>{{ change.rev }}:{{ change.node[:12] }}</td>
+ <td><a href="{{ adapter.get_branch_url(change) }}">{{ change.branch }}</a></td>
+ <td><a href="{{ adapter.get_commit_url(change) }}">{{ change.rev }}:{{ change.node[:12] }}</a></td>
<td class="uk-width-1-1 uk-text-break">
<div>{{ change.message }}</div>
<div>{{ change.author }}, {% module Time(change.date, False) %}</div>