Eliminate duplicate getPreviousBuild functions
And move some stuff into CatalystUtils for use by other plugins.
This commit is contained in:
parent
c65f40e146
commit
698d6eac89
|
@ -24,7 +24,7 @@ sub build : Chained('/') PathPart CaptureArgs(1) {
|
|||
notFound($c, "Build with ID $id doesn't exist.")
|
||||
if !defined $c->stash->{build};
|
||||
|
||||
$c->stash->{prevBuild} = getPreviousBuild($c, $c->stash->{build});
|
||||
$c->stash->{prevBuild} = getPreviousBuild($c->stash->{build});
|
||||
$c->stash->{prevSuccessfulBuild} = getPreviousSuccessfulBuild($c, $c->stash->{build});
|
||||
$c->stash->{firstBrokenBuild} = getNextBuild($c, $c->stash->{prevSuccessfulBuild});
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use Email::Sender::Transport::SMTP;
|
|||
use Sys::Hostname::Long;
|
||||
use Nix::Store;
|
||||
use Hydra::Helper::Nix;
|
||||
use feature qw/switch/;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
|
@ -18,12 +19,14 @@ our @EXPORT = qw(
|
|||
requireLogin requireProjectOwner requireAdmin requirePost isAdmin isProjectOwner
|
||||
trim
|
||||
getLatestFinishedEval
|
||||
parseJobsetName
|
||||
sendEmail
|
||||
paramToList
|
||||
backToReferer
|
||||
$pathCompRE $relPathRE $relNameRE $projectNameRE $jobsetNameRE $jobNameRE $systemRE $userNameRE
|
||||
@buildListColumns
|
||||
parseJobsetName
|
||||
showJobName
|
||||
showStatus
|
||||
);
|
||||
|
||||
|
||||
|
@ -39,19 +42,14 @@ sub getBuild {
|
|||
|
||||
|
||||
sub getPreviousBuild {
|
||||
my ($c, $build) = @_;
|
||||
my ($build) = @_;
|
||||
return undef if !defined $build;
|
||||
|
||||
(my $prevBuild) = $c->model('DB::Builds')->search(
|
||||
return $build->job->builds->search(
|
||||
{ finished => 1
|
||||
, system => $build->system
|
||||
, project => $build->project->name
|
||||
, jobset => $build->jobset->name
|
||||
, job => $build->job->name
|
||||
, 'me.id' => { '<' => $build->id }
|
||||
}, {rows => 1, order_by => "me.id DESC"});
|
||||
|
||||
return $prevBuild;
|
||||
, -not => { buildstatus => { -in => [4, 3]} }
|
||||
}, { rows => 1, order_by => "me.id DESC" })->single;
|
||||
}
|
||||
|
||||
|
||||
|
@ -230,4 +228,26 @@ sub parseJobsetName {
|
|||
}
|
||||
|
||||
|
||||
sub showJobName {
|
||||
my ($build) = @_;
|
||||
return $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name;
|
||||
}
|
||||
|
||||
|
||||
sub showStatus {
|
||||
my ($build) = @_;
|
||||
|
||||
my $status = "Failed";
|
||||
given ($build->buildstatus) {
|
||||
when (0) { $status = "Success"; }
|
||||
when (1) { $status = "Failed"; }
|
||||
when (2) { $status = "Dependency failed"; }
|
||||
when (4) { $status = "Cancelled"; }
|
||||
when (6) { $status = "Failed with output"; }
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
@ -2,7 +2,6 @@ package Hydra::Plugin::EmailNotification;
|
|||
|
||||
use strict;
|
||||
use parent 'Hydra::Plugin';
|
||||
use feature qw/switch/;
|
||||
use POSIX qw(strftime);
|
||||
use Email::Sender::Simple qw(sendmail);
|
||||
use Email::Sender::Transport::SMTP;
|
||||
|
@ -15,43 +14,6 @@ use Hydra::Helper::Nix;
|
|||
use Hydra::Helper::CatalystUtils;
|
||||
|
||||
|
||||
sub showStatus {
|
||||
my ($build) = @_;
|
||||
|
||||
my $status = "Failed";
|
||||
given ($build->buildstatus) {
|
||||
when (0) { $status = "Success"; }
|
||||
when (1) { $status = "Failed"; }
|
||||
when (2) { $status = "Dependency failed"; }
|
||||
when (4) { $status = "Cancelled"; }
|
||||
when (6) { $status = "Failed with output"; }
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
sub showJobName {
|
||||
my ($build) = @_;
|
||||
return $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name;
|
||||
}
|
||||
|
||||
|
||||
sub getPrevBuild {
|
||||
my ($self, $build) = @_;
|
||||
return $self->{db}->resultset('Builds')->search(
|
||||
{ project => $build->project->name
|
||||
, jobset => $build->jobset->name
|
||||
, job => $build->job->name
|
||||
, system => $build->system
|
||||
, finished => 1
|
||||
, id => { '<', $build->id }
|
||||
, -not => { buildstatus => { -in => [4, 3]} }
|
||||
}, { order_by => ["id DESC"], rows => 1 }
|
||||
)->single;
|
||||
}
|
||||
|
||||
|
||||
my $template = <<EOF;
|
||||
Hi,
|
||||
|
||||
|
@ -89,7 +51,7 @@ sub buildFinished {
|
|||
# relevant builds for that address.
|
||||
my %addresses;
|
||||
foreach my $b ($build, @{$dependents}) {
|
||||
my $prevBuild = getPrevBuild($self, $b);
|
||||
my $prevBuild = getPreviousBuild($b);
|
||||
my $to = $b->jobset->emailoverride ne "" ? $b->jobset->emailoverride : $b->maintainers;
|
||||
|
||||
foreach my $address (split ",", $to) {
|
||||
|
@ -122,7 +84,7 @@ sub buildFinished {
|
|||
my $tt = Template->new({});
|
||||
|
||||
my $vars =
|
||||
{ build => $build, prevBuild => getPrevBuild($self, $build)
|
||||
{ build => $build, prevBuild => getPreviousBuild($build)
|
||||
, dependents => [grep { $_->id != $build->id } @builds]
|
||||
, baseurl => $self->{config}->{'base_uri'} || "http://localhost:3000"
|
||||
, showJobName => \&showJobName, showStatus => \&showStatus
|
||||
|
|
Loading…
Reference in a new issue