EmailNotification: $build -> $topbuild, $b -> $build (perlcritic)
This commit is contained in:
parent
0f88014631
commit
0d4ce15c62
|
@ -46,46 +46,46 @@ EOF
|
||||||
|
|
||||||
|
|
||||||
sub buildFinished {
|
sub buildFinished {
|
||||||
my ($self, $build, $dependents) = @_;
|
my ($self, $topbuild, $dependents) = @_;
|
||||||
|
|
||||||
die unless $build->finished;
|
die unless $topbuild->finished;
|
||||||
|
|
||||||
# Figure out to whom to send notification for each build. For
|
# Figure out to whom to send notification for each build. For
|
||||||
# each email address, we send one aggregate email listing only the
|
# each email address, we send one aggregate email listing only the
|
||||||
# relevant builds for that address.
|
# relevant builds for that address.
|
||||||
my %addresses;
|
my %addresses;
|
||||||
foreach my $b ($build, @{$dependents}) {
|
foreach my $build ($topbuild, @{$dependents}) {
|
||||||
my $prevBuild = getPreviousBuild($b);
|
my $prevBuild = getPreviousBuild($build);
|
||||||
# Do we want to send mail for this build?
|
# Do we want to send mail for this build?
|
||||||
unless ($ENV{'HYDRA_FORCE_SEND_MAIL'}) {
|
unless ($ENV{'HYDRA_FORCE_SEND_MAIL'}) {
|
||||||
next unless $b->jobset->enableemail;
|
next unless $build->jobset->enableemail;
|
||||||
|
|
||||||
# If build is cancelled or aborted, do not send email.
|
# If build is cancelled or aborted, do not send email.
|
||||||
next if $b->buildstatus == 4 || $b->buildstatus == 3;
|
next if $build->buildstatus == 4 || $build->buildstatus == 3;
|
||||||
|
|
||||||
# If there is a previous (that is not cancelled or aborted) build
|
# If there is a previous (that is not cancelled or aborted) build
|
||||||
# with same buildstatus, do not send email.
|
# with same buildstatus, do not send email.
|
||||||
next if defined $prevBuild && ($b->buildstatus == $prevBuild->buildstatus);
|
next if defined $prevBuild && ($build->buildstatus == $prevBuild->buildstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
my $to = $b->jobset->emailoverride ne "" ? $b->jobset->emailoverride : $b->maintainers;
|
my $to = $build->jobset->emailoverride ne "" ? $build->jobset->emailoverride : $build->maintainers;
|
||||||
|
|
||||||
foreach my $address (split ",", ($to // "")) {
|
foreach my $address (split ",", ($to // "")) {
|
||||||
$address = trim $address;
|
$address = trim $address;
|
||||||
|
|
||||||
$addresses{$address} //= { builds => [] };
|
$addresses{$address} //= { builds => [] };
|
||||||
push @{$addresses{$address}->{builds}}, $b;
|
push @{$addresses{$address}->{builds}}, $build;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($authors, $nrCommits, $emailable_authors) = getResponsibleAuthors($build, $self->{plugins});
|
my ($authors, $nrCommits, $emailable_authors) = getResponsibleAuthors($topbuild, $self->{plugins});
|
||||||
my $authorList;
|
my $authorList;
|
||||||
my $prevBuild = getPreviousBuild($build);
|
my $prevBuild = getPreviousBuild($topbuild);
|
||||||
if (scalar keys %{$authors} > 0 &&
|
if (scalar keys %{$authors} > 0 &&
|
||||||
((!defined $prevBuild) || ($build->buildstatus != $prevBuild->buildstatus))) {
|
((!defined $prevBuild) || ($topbuild->buildstatus != $prevBuild->buildstatus))) {
|
||||||
my @x = map { "$_ <$authors->{$_}>" } (sort keys %{$authors});
|
my @x = map { "$_ <$authors->{$_}>" } (sort keys %{$authors});
|
||||||
$authorList = join(" or ", scalar @x > 1 ? join(", ", @x[0..scalar @x - 2]): (), $x[-1]);
|
$authorList = join(" or ", scalar @x > 1 ? join(", ", @x[0..scalar @x - 2]): (), $x[-1]);
|
||||||
$addresses{$_} = { builds => [ $build ] } foreach (@{$emailable_authors});
|
$addresses{$_} = { builds => [ $topbuild ] } foreach (@{$emailable_authors});
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send an email to each interested address.
|
# Send an email to each interested address.
|
||||||
|
@ -96,11 +96,11 @@ sub buildFinished {
|
||||||
my $tt = Template->new({});
|
my $tt = Template->new({});
|
||||||
|
|
||||||
my $vars =
|
my $vars =
|
||||||
{ build => $build, prevBuild => getPreviousBuild($build)
|
{ build => $topbuild, prevBuild => getPreviousBuild($topbuild)
|
||||||
, dependents => [grep { $_->id != $build->id } @builds]
|
, dependents => [grep { $_->id != $topbuild->id } @builds]
|
||||||
, baseurl => getBaseUrl($self->{config})
|
, baseurl => getBaseUrl($self->{config})
|
||||||
, showJobName => \&showJobName, showStatus => \&showStatus
|
, showJobName => \&showJobName, showStatus => \&showStatus
|
||||||
, showSystem => index($build->get_column('job'), $build->system) == -1
|
, showSystem => index($topbuild->get_column('job'), $topbuild->system) == -1
|
||||||
, nrCommits => $nrCommits
|
, nrCommits => $nrCommits
|
||||||
, authorList => $authorList
|
, authorList => $authorList
|
||||||
};
|
};
|
||||||
|
@ -113,16 +113,16 @@ sub buildFinished {
|
||||||
$body =~ s/[\ ]+$//gm;
|
$body =~ s/[\ ]+$//gm;
|
||||||
|
|
||||||
my $subject =
|
my $subject =
|
||||||
showStatus($build) . ": Hydra job " . showJobName($build)
|
showStatus($topbuild) . ": Hydra job " . showJobName($topbuild)
|
||||||
. ($vars->{showSystem} ? " on " . $build->system : "")
|
. ($vars->{showSystem} ? " on " . $topbuild->system : "")
|
||||||
. (scalar @{$vars->{dependents}} > 0 ? " (and " . scalar @{$vars->{dependents}} . " others)" : "");
|
. (scalar @{$vars->{dependents}} > 0 ? " (and " . scalar @{$vars->{dependents}} . " others)" : "");
|
||||||
|
|
||||||
sendEmail(
|
sendEmail(
|
||||||
$self->{config}, $to, $subject, $body,
|
$self->{config}, $to, $subject, $body,
|
||||||
[ 'X-Hydra-Project' => $build->get_column('project'),
|
[ 'X-Hydra-Project' => $topbuild->get_column('project'),
|
||||||
, 'X-Hydra-Jobset' => $build->get_column('jobset'),
|
, 'X-Hydra-Jobset' => $topbuild->get_column('jobset'),
|
||||||
, 'X-Hydra-Job' => $build->get_column('job'),
|
, 'X-Hydra-Job' => $topbuild->get_column('job'),
|
||||||
, 'X-Hydra-System' => $build->system
|
, 'X-Hydra-System' => $topbuild->system
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue