Fix rendering of metrics with special characters
My main motivation here is to get metrics with brackets to work in order to support "pytest" test names: - test_foo.py::test_bar[1] - test_foo.py::test_bar[2] I couldn't find an "HTML escape"-style function that would generate valid html `id` attribute names from random strings, so I went with a hash digest instead.
This commit is contained in:
parent
90a8a0d94a
commit
590e8d8511
@ -6,6 +6,7 @@ use base 'Catalyst::View::TT';
|
|||||||
use Template::Plugin::HTML;
|
use Template::Plugin::HTML;
|
||||||
use Hydra::Helper::Nix;
|
use Hydra::Helper::Nix;
|
||||||
use Time::Seconds;
|
use Time::Seconds;
|
||||||
|
use Digest::SHA qw(sha1_hex);
|
||||||
|
|
||||||
__PACKAGE__->config(
|
__PACKAGE__->config(
|
||||||
TEMPLATE_EXTENSION => '.tt',
|
TEMPLATE_EXTENSION => '.tt',
|
||||||
@ -25,8 +26,14 @@ __PACKAGE__->config(
|
|||||||
makeNameTextForJobset
|
makeNameTextForJobset
|
||||||
relativeDuration
|
relativeDuration
|
||||||
stripSSHUser
|
stripSSHUser
|
||||||
|
metricDivId
|
||||||
/]);
|
/]);
|
||||||
|
|
||||||
|
sub metricDivId {
|
||||||
|
my ($self, $c, $text) = @_;
|
||||||
|
return "metric-" . sha1_hex($text);
|
||||||
|
}
|
||||||
|
|
||||||
sub buildLogExists {
|
sub buildLogExists {
|
||||||
my ($self, $c, $build) = @_;
|
my ($self, $c, $build) = @_;
|
||||||
return 1 if defined $c->config->{log_prefix};
|
return 1 if defined $c->config->{log_prefix};
|
||||||
|
@ -18,8 +18,7 @@
|
|||||||
|
|
||||||
<h3>Metric: <a [% HTML.attributes(href => c.uri_for('/job' project.name jobset.name job 'metric' metric.name)) %]><tt>[%HTML.escape(metric.name)%]</tt></a></h3>
|
<h3>Metric: <a [% HTML.attributes(href => c.uri_for('/job' project.name jobset.name job 'metric' metric.name)) %]><tt>[%HTML.escape(metric.name)%]</tt></a></h3>
|
||||||
|
|
||||||
[% id = "metric-" _ metric.name;
|
[% id = metricDivId(metric.name);
|
||||||
id = id.replace('\.', '_');
|
|
||||||
INCLUDE createChart dataUrl=c.uri_for('/job' project.name jobset.name job 'metric' metric.name); %]
|
INCLUDE createChart dataUrl=c.uri_for('/job' project.name jobset.name job 'metric' metric.name); %]
|
||||||
|
|
||||||
[% END %]
|
[% END %]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user