TT: add helpers for linking to jobs, jobsets, and projects, and for generating colon separated names.

[?]
Nov 22, 2021, 6:14 PM
LYRHVDS2Z6V565364MAYFDZKGRZD2WBZBLK7UZWH664IS7T656AAC

Dependencies

  • [2] 2JJP7673 tests: move to t, allow `yath test` from root
  • [3] S3ETHAGK Show evaluation time in the evaluations overview
  • [4] Y6AHH4TH Remove the logfile and logSize columns from the database
  • [5] O757ISIS Remove unused function
  • [6] XKXMU5PV Ellipsize long jobset/job names to prevent bootstrap navbar breakage
  • [7] JPTXSWBO Show whether a job still exists
  • [8] ZH6B56XR Try harder to find build logs
  • [9] HOMDMC3K Handle utf-8 properly
  • [10] XO72X6PQ Handle SSH hosts without a @
  • [11] OZDDUMVP Automatically chomp all [%...%] directives
  • [*] J5UVLXOK * Start of a basic Catalyst web interface.
  • [*] NZXX6PLD Remove the Jobs table

Change contents

  • edit in src/lib/Hydra/View/TT.pm at line 6
    [13.6867]
    [4.9641]
    use Template::Plugin::HTML;
  • replacement in src/lib/Hydra/View/TT.pm at line 15
    [4.41][3.20:124]()
    expose_methods => [qw/buildLogExists buildStepLogExists jobExists relativeDuration stripSSHUser/]);
    [4.41]
    [4.2156]
    expose_methods => [qw/
    buildLogExists
    buildStepLogExists
    jobExists
    linkToJob
    linkToJobset
    linkToProject
    makeNameLinksForJob
    makeNameLinksForJobset
    makeNameTextForJob
    makeNameTextForJobset
    relativeDuration
    stripSSHUser
    /]);
  • edit in src/lib/Hydra/View/TT.pm at line 79
    [14.3416]
    [4.476]
    }
    =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;
  • edit in src/lib/Hydra/View/TT.pm at line 262
    [4.479]
    [13.6919]
    =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;
    }
  • file addition: View (d--r------)
    [2.697]
  • file addition: TT.t (----------)
    [0.4451]
    use feature 'unicode_strings';
    use strict;
    use warnings;
    use Setup;
    my %ctx = test_init();
    require Hydra::Schema;
    require Hydra::Model::DB;
    use Test2::V0;
    require Hydra; # calls setup()
    my $db = Hydra::Model::DB->new;
    hydra_setup($db);
    require Hydra::View::TT;
    # The following lines are a cheap and hacky trick to get $c,
    # there is no other reason to call /.
    require Catalyst::Test;
    Catalyst::Test->import('Hydra');
    my($_, $c) = ctx_request('/');
    my $project = $db->resultset('Projects')->create({name => "tests", displayname => "", owner => "root"});
    my $jobset = createBaseJobset("example", "bogus.nix", $ctx{jobsdir});
    my $job = "myjob";
    is(
    Hydra::View::TT::linkToProject(undef, $c, $project),
    '<a href="http://localhost/project/tests">tests</a>',
    "linkToProject"
    );
    is(
    Hydra::View::TT::linkToJobset(undef, $c, $jobset),
    '<a href="http://localhost/project/tests">tests</a>:'
    . '<a href="http://localhost/jobset/tests/example">example</a>',
    "linkToJobset"
    );
    is(
    Hydra::View::TT::linkToJob(undef, $c, $jobset, $job),
    '<a href="http://localhost/project/tests">tests</a>:'
    . '<a href="http://localhost/jobset/tests/example">example</a>:'
    . '<a href="http://localhost/job/tests/example/myjob">myjob</a>',
    "linkToJob"
    );
    is(
    Hydra::View::TT::makeNameLinksForJobset(undef, $c, $jobset),
    '<a href="http://localhost/project/tests">tests</a>'
    . ':example',
    "makeNameLinksForJobset"
    );
    is(
    Hydra::View::TT::makeNameLinksForJob(undef, $c, $jobset, $job),
    '<a href="http://localhost/project/tests">tests</a>:'
    . '<a href="http://localhost/jobset/tests/example">example</a>'
    . ':myjob',
    "makeNameLinksForJob"
    );
    is(
    Hydra::View::TT::makeNameTextForJobset(undef, $c, $jobset),
    'tests:example',
    "makeNameTextForJobset"
    );
    is(
    Hydra::View::TT::makeNameTextForJob(undef, $c, $jobset, $job),
    'tests:example:myjob',
    "makeNameTextForJob"
    );
    done_testing;