hydra/src/lib/Hydra/Base/Controller/ListBuilds.pm

61 lines
1.8 KiB
Perl
Raw Normal View History

package Hydra::Base::Controller::ListBuilds;
use strict;
use warnings;
use base 'Hydra::Base::Controller::NixChannel';
use Hydra::Helper::Nix;
use Hydra::Helper::CatalystUtils;
sub jobstatus : Chained('get_builds') PathPart Args(0) {
my ($self, $c) = @_;
$c->stash->{template} = 'jobstatus.tt';
2009-03-13 17:32:08 +00:00
my $jobs = $c->stash->{allJobs};
$c->stash->{latestBuilds} =
getLatestBuilds($c, ref $jobs eq "ARRAY" ? $jobs : scalar $jobs->search({active => 1}), {});
}
sub all : Chained('get_builds') PathPart {
my ($self, $c, $page) = @_;
$c->stash->{template} = 'all.tt';
$page = (defined $page ? int($page) : 1) || 1;
my $resultsPerPage = 50;
my $nrBuilds = scalar($c->stash->{allBuilds}->search({finished => 1}));
$c->stash->{baseUri} = $c->uri_for($self->action_for("all"), $c->req->captures);
$c->stash->{page} = $page;
$c->stash->{resultsPerPage} = $resultsPerPage;
$c->stash->{totalBuilds} = $nrBuilds;
$c->stash->{builds} = [$c->stash->{allBuilds}->search(
{finished => 1}, {order_by => "timestamp DESC", rows => $resultsPerPage, page => $page})];
}
sub nix : Chained('get_builds') PathPart('channel') CaptureArgs(1) {
my ($self, $c, $channelName) = @_;
eval {
if ($channelName eq "latest") {
$c->stash->{channelName} = $c->stash->{channelBaseName} . "-latest";
2009-03-13 17:32:08 +00:00
getChannelData($c, getLatestBuilds($c, scalar $c->stash->{allJobs}->search({active => 1}), {buildStatus => 0}));
}
elsif ($channelName eq "all") {
$c->stash->{channelName} = $c->stash->{channelBaseName} . "-all";
getChannelData($c, [$c->stash->{allBuilds}->all]);
}
else {
error($c, "Unknown channel `$channelName'.");
}
};
error($c, $@) if $@;
}
1;