TT: add helpers for linking to jobs, jobsets, and projects, and for generating colon separated names.
This commit is contained in:
@ -3,6 +3,7 @@ package Hydra::View::TT;
|
||||
use strict;
|
||||
use warnings;
|
||||
use base 'Catalyst::View::TT';
|
||||
use Template::Plugin::HTML;
|
||||
use Hydra::Helper::Nix;
|
||||
use Time::Seconds;
|
||||
|
||||
@ -11,7 +12,20 @@ __PACKAGE__->config(
|
||||
ENCODING => 'utf-8',
|
||||
PRE_CHOMP => 1,
|
||||
POST_CHOMP => 1,
|
||||
expose_methods => [qw/buildLogExists buildStepLogExists jobExists relativeDuration stripSSHUser/]);
|
||||
expose_methods => [qw/
|
||||
buildLogExists
|
||||
buildStepLogExists
|
||||
jobExists
|
||||
linkToJob
|
||||
linkToJobset
|
||||
linkToProject
|
||||
makeNameLinksForJob
|
||||
makeNameLinksForJobset
|
||||
makeNameTextForJob
|
||||
makeNameTextForJobset
|
||||
relativeDuration
|
||||
stripSSHUser
|
||||
/]);
|
||||
|
||||
sub buildLogExists {
|
||||
my ($self, $c, $build) = @_;
|
||||
@ -64,4 +78,250 @@ sub jobExists {
|
||||
return defined $jobset->builds->search({ job => $jobName, iscurrent => 1 })->single;
|
||||
}
|
||||
|
||||
=head2 linkToProject
|
||||
|
||||
Given a L<Hydra::Schema::Result::Project>, return a link to the project.
|
||||
|
||||
Arguments:
|
||||
|
||||
=over 3
|
||||
|
||||
=item C<$self>
|
||||
=back
|
||||
|
||||
=item C<$c>
|
||||
Catalyst Context
|
||||
=back
|
||||
|
||||
=item C<$project>
|
||||
|
||||
The L<Hydra::Schema::Result::Project> to link to.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
sub linkToProject {
|
||||
my ($self, $c, $project) = @_;
|
||||
|
||||
my $html = Template::Plugin::HTML->new();
|
||||
|
||||
my $projectName = $project->name;
|
||||
my $escapedProjectName = $html->escape($projectName);
|
||||
|
||||
return '<a href="' . $c->uri_for('/project', $projectName) . '">' . $escapedProjectName . '</a>';
|
||||
}
|
||||
|
||||
=head2 linkToJobset
|
||||
|
||||
Given a L<Hydra::Schema::Result::Jobset>, return a link to the jobset
|
||||
and its project in project:jobset notation.
|
||||
|
||||
Arguments:
|
||||
|
||||
=over 3
|
||||
|
||||
=item C<$self>
|
||||
=back
|
||||
|
||||
=item C<$c>
|
||||
Catalyst Context
|
||||
=back
|
||||
|
||||
=item C<$jobset>
|
||||
|
||||
The L<Hydra::Schema::Result::Jobset> to link to.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
sub linkToJobset {
|
||||
my ($self, $c, $jobset) = @_;
|
||||
|
||||
my $html = Template::Plugin::HTML->new();
|
||||
|
||||
my $jobsetName = $jobset->name;
|
||||
my $escapedJobsetName = $html->escape($jobsetName);
|
||||
|
||||
return linkToProject($self, $c, $jobset->project) .
|
||||
':<a href="' . $c->uri_for('/jobset', $jobset->project->name, $jobsetName) . '">' . $escapedJobsetName . '</a>';
|
||||
}
|
||||
|
||||
=head2 linkToJobset
|
||||
|
||||
Given a L<Hydra::Schema::Result::Jobset> and L<String> Job name, return
|
||||
a link to the job, jobset, and project in project:jobset:job notation.
|
||||
|
||||
Arguments:
|
||||
|
||||
=over 4
|
||||
|
||||
=item C<$self>
|
||||
=back
|
||||
|
||||
=item C<$c>
|
||||
Catalyst Context
|
||||
=back
|
||||
|
||||
=item C<$jobset>
|
||||
|
||||
The L<Hydra::Schema::Result::Jobset> to link to.
|
||||
=back
|
||||
|
||||
=item C<$jobName>
|
||||
|
||||
The L<String> job name to link to.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
sub linkToJob {
|
||||
my ($self, $c, $jobset, $jobName) = @_;
|
||||
|
||||
my $html = Template::Plugin::HTML->new();
|
||||
|
||||
my $escapedJobName = $html->escape($jobName);
|
||||
|
||||
return linkToJobset($self, $c, $jobset) .
|
||||
':<a href="' . $c->uri_for('/job', $jobset->project->name, $jobset->name, $jobName) . '">' . $escapedJobName . '</a>';
|
||||
}
|
||||
|
||||
=head2 makeNameLinksForJobset
|
||||
|
||||
Given a L<Hydra::Schema::Result::Jobset>, return a link to the jobset's
|
||||
project and a non-link to the jobset in project:jobset notation.
|
||||
|
||||
Arguments:
|
||||
|
||||
=over 3
|
||||
|
||||
=item C<$self>
|
||||
=back
|
||||
|
||||
=item C<$c>
|
||||
Catalyst Context
|
||||
=back
|
||||
|
||||
=item C<$jobset>
|
||||
|
||||
The L<Hydra::Schema::Result::Jobset> to link to.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
sub makeNameLinksForJobset {
|
||||
my ($self, $c, $jobset) = @_;
|
||||
|
||||
my $html = Template::Plugin::HTML->new();
|
||||
|
||||
my $escapedJobsetName = $html->escape($jobset->name);
|
||||
|
||||
return linkToProject($self, $c, $jobset->project) . ':' . $escapedJobsetName;
|
||||
}
|
||||
|
||||
=head2 makeNameLinksForJob
|
||||
|
||||
Given a L<Hydra::Schema::Result::Jobset> and L<String> Job name, return
|
||||
a link to the jobset and project, and a non-link to the job in
|
||||
project:jobset:job notation.
|
||||
|
||||
Arguments:
|
||||
|
||||
=over 4
|
||||
|
||||
=item C<$self>
|
||||
=back
|
||||
|
||||
=item C<$c>
|
||||
Catalyst Context
|
||||
=back
|
||||
|
||||
=item C<$jobset>
|
||||
|
||||
The L<Hydra::Schema::Result::Jobset> to link to.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=item C<$jobName>
|
||||
|
||||
The L<String> job name to link to.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
sub makeNameLinksForJob {
|
||||
my ($self, $c, $jobset, $jobName) = @_;
|
||||
|
||||
my $html = Template::Plugin::HTML->new();
|
||||
|
||||
my $escapedJobName = $html->escape($jobName);
|
||||
|
||||
return linkToJobset($self, $c, $jobset) . ':' . $escapedJobName;
|
||||
}
|
||||
|
||||
=head2 makeNameTextForJobset
|
||||
|
||||
Given a L<Hydra::Schema::Result::Jobset>, return the project and
|
||||
jobset in project:jobset notation.
|
||||
|
||||
Arguments:
|
||||
|
||||
=over 3
|
||||
|
||||
=item C<$self>
|
||||
=back
|
||||
|
||||
=item C<$c>
|
||||
Catalyst Context
|
||||
=back
|
||||
|
||||
=item C<$jobset>
|
||||
|
||||
The L<Hydra::Schema::Result::Jobset> to link to.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
sub makeNameTextForJobset {
|
||||
my ($self, $c, $jobset) = @_;
|
||||
|
||||
return $jobset->project->name . ":" . $jobset->name;
|
||||
}
|
||||
|
||||
=head2 makeNameTextForJob
|
||||
|
||||
Given a L<Hydra::Schema::Result::Jobset> and L<String> Job name, return
|
||||
the job, jobset, and project in project:jobset:job notation.
|
||||
|
||||
Arguments:
|
||||
|
||||
=over 4
|
||||
|
||||
=item C<$self>
|
||||
=back
|
||||
|
||||
=item C<$c>
|
||||
Catalyst Context
|
||||
=back
|
||||
|
||||
=item C<$jobset>
|
||||
|
||||
The L<Hydra::Schema::Result::Jobset> to link to.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=item C<$jobName>
|
||||
|
||||
The L<String> job name to link to.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
sub makeNameTextForJob {
|
||||
my ($self, $c, $jobset, $jobName) = @_;
|
||||
|
||||
return $jobset->project->name . ":" . $jobset->name . ":" . $jobName;
|
||||
}
|
||||
|
||||
1;
|
||||
|
Reference in New Issue
Block a user