Download:
child 111:b26943a3d16f
parent 109:6cbbab799f3c
110:6b22a1b4b85c
Anton Shestakov <av6@dwimlabs.net>, Tue, 05 Jul 2016 21:02:50 +0800
viewer: provide links to file/line on warnings/errors in check logs

4 файлов изменено, 32 вставок(+), 1 удалений(-) [+]
candolint/adapters.py file | annotate | diff | comparison | revisions
candolint/handlers.py file | annotate | diff | comparison | revisions
static/main.css file | annotate | diff | comparison | revisions
templates/check.html file | annotate | diff | comparison | revisions
--- a/candolint/adapters.py Tue Jul 05 20:48:01 2016 +0800
+++ b/candolint/adapters.py Tue Jul 05 21:02:50 2016 +0800
@@ -1,3 +1,6 @@
+from os.path import basename
+
+
class HostingAdapter(object):
def __init__(self, project):
self.project = project
@@ -8,6 +11,9 @@
def get_branch_url(self, change):
return ''
+ def get_line_url(self, change, line):
+ return ''
+
class BitbucketAdapter(HostingAdapter):
def get_commit_url(self, change):
@@ -21,3 +27,12 @@
'url': self.project.url,
'branch': change.branch
})
+
+ def get_line_url(self, change, line):
+ return '{url}/src/{node}/{filename}#{basename}-{line_number}'.format(**{
+ 'url': self.project.url,
+ 'node': change.node,
+ 'filename': line['filename'],
+ 'basename': basename(line['filename']),
+ 'line_number': line['line_number']
+ })
--- a/candolint/handlers.py Tue Jul 05 20:48:01 2016 +0800
+++ b/candolint/handlers.py Tue Jul 05 21:02:50 2016 +0800
@@ -93,6 +93,9 @@
def get_html(self, project, check, lines):
adapter = project.get_adapter()
+ for line in lines:
+ if 'filename' in line:
+ line['link'] = adapter.get_line_url(check.change, line)
self.render('check.html', project=project, check=check, lines=lines, adapter=adapter)
--- a/static/main.css Tue Jul 05 20:48:01 2016 +0800
+++ b/static/main.css Tue Jul 05 21:02:50 2016 +0800
@@ -110,6 +110,11 @@
padding-right: 10px;
}
+.check-log a.filelink {
+ color: inherit;
+ text-decoration: underline;
+}
+
.check-log a.collapser {
margin-left: 8px;
color: inherit;
--- a/templates/check.html Tue Jul 05 20:48:01 2016 +0800
+++ b/templates/check.html Tue Jul 05 21:02:50 2016 +0800
@@ -49,7 +49,15 @@
#}{% for number, line in enumerate(lines, 1) %}{#
#}<div id="l{{ number }}"{% if 'task' in line %} data-task="{{ line['task'] }}"{% end %}{% if 'cls' in line %} class="{{ line['cls'] }}"{% end %}>{#
#}<a href="#l{{ number }}" class="lineno" data-line-number="{{ number }}"></a>{#
- #}{{ line['text'] }}{#
+ #}{% if 'link' in line %}{#
+ #}{{ line['text'][:line['link_start']] }}{#
+ #}<a href="{{ line['link'] }}" class="filelink">{#
+ #}{{ line['text'][line['link_start']:line['link_end']] }}{#
+ #}</a>{#
+ #}{{ line['text'][line['link_end']:] }}{#
+ #}{% else %}{#
+ #}{{ line['text'] }}{#
+ #}{% end %}{#
#}</div>{#
#}{% end %}{#
#}</pre>