Merge pull request #1004 from DeterminateSystems/avoid-a-b

Avoid $a, $b
This commit is contained in:
Graham Christensen 2021-09-06 21:35:17 -04:00 committed by GitHub
commit dd06ab7a99
13 changed files with 115 additions and 115 deletions

View file

@ -121,10 +121,10 @@ sub overview : Chained('job') PathPart('') Args(0) {
my $aggregates = {}; my $aggregates = {};
my %constituentJobs; my %constituentJobs;
foreach my $b (@constituents) { foreach my $build (@constituents) {
$aggregates->{$b->get_column('aggregate')}->{constituents}->{$b->job} = $aggregates->{$build->get_column('aggregate')}->{constituents}->{$build->job} =
{ id => $b->id, finished => $b->finished, buildstatus => $b->buildstatus }; { id => $build->id, finished => $build->finished, buildstatus => $build->buildstatus };
$constituentJobs{$b->job} = 1; $constituentJobs{$build->job} = 1;
} }
foreach my $agg (keys %$aggregates) { foreach my $agg (keys %$aggregates) {

View file

@ -64,9 +64,9 @@ sub view_GET {
$c->stash->{otherEval} = $eval2 if defined $eval2; $c->stash->{otherEval} = $eval2 if defined $eval2;
sub cmpBuilds { sub cmpBuilds {
my ($a, $b) = @_; my ($left, $right) = @_;
return $a->get_column('job') cmp $b->get_column('job') return $left->get_column('job') cmp $right->get_column('job')
|| $a->get_column('system') cmp $b->get_column('system') || $left->get_column('system') cmp $right->get_column('system')
} }
my @builds = $eval->builds->search($filter, { columns => [@buildListColumns] }); my @builds = $eval->builds->search($filter, { columns => [@buildListColumns] });

View file

@ -53,9 +53,9 @@ sub execute {
# #
# Otherwise, the dependent builds will remain with notificationpendingsince set # Otherwise, the dependent builds will remain with notificationpendingsince set
# until hydra-notify is started, as buildFinished is never emitted for them. # until hydra-notify is started, as buildFinished is never emitted for them.
foreach my $b ($self->{"build"}, @{$self->{"dependents"}}) { foreach my $build ($self->{"build"}, @{$self->{"dependents"}}) {
if ($b->finished && defined($b->notificationpendingsince)) { if ($build->finished && defined($build->notificationpendingsince)) {
$b->update({ notificationpendingsince => undef }) $build->update({ notificationpendingsince => undef })
} }
} }

View file

@ -109,14 +109,14 @@ sub searchBuildsAndEvalsForJobset {
{ columns => ['id', 'job', 'finished', 'buildstatus'] } { columns => ['id', 'job', 'finished', 'buildstatus'] }
); );
foreach my $b (@allBuilds) { foreach my $build (@allBuilds) {
my $jobName = $b->get_column('job'); my $jobName = $build->get_column('job');
$evals->{$eval->id}->{timestamp} = $eval->timestamp; $evals->{$eval->id}->{timestamp} = $eval->timestamp;
$evals->{$eval->id}->{builds}->{$jobName} = { $evals->{$eval->id}->{builds}->{$jobName} = {
id => $b->id, id => $build->id,
finished => $b->finished, finished => $build->finished,
buildstatus => $b->buildstatus buildstatus => $build->buildstatus
}; };
$builds{$jobName} = 1; $builds{$jobName} = 1;
$nrBuilds++; $nrBuilds++;

View file

@ -22,21 +22,21 @@ sub toBitBucketState {
} }
sub common { sub common {
my ($self, $build, $dependents, $finished) = @_; my ($self, $topbuild, $dependents, $finished) = @_;
my $bitbucket = $self->{config}->{bitbucket}; my $bitbucket = $self->{config}->{bitbucket};
my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000"; my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000";
foreach my $b ($build, @{$dependents}) { foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $b; my $jobName = showJobName $build;
my $evals = $build->jobsetevals; my $evals = $topbuild->jobsetevals;
my $ua = LWP::UserAgent->new(); my $ua = LWP::UserAgent->new();
my $body = encode_json( my $body = encode_json(
{ {
state => $finished ? toBitBucketState($b->buildstatus) : "INPROGRESS", state => $finished ? toBitBucketState($build->buildstatus) : "INPROGRESS",
url => "$baseurl/build/" . $b->id, url => "$baseurl/build/" . $build->id,
name => $jobName, name => $jobName,
key => $b->id, key => $build->id,
description => "Hydra build #" . $b->id . " of $jobName", description => "Hydra build #" . $build->id . " of $jobName",
}); });
while (my $eval = $evals->next) { while (my $eval = $evals->next) {
foreach my $i ($eval->jobsetevalinputs){ foreach my $i ($eval->jobsetevalinputs){

View file

@ -13,22 +13,22 @@ sub isEnabled {
} }
sub buildFinished { sub buildFinished {
my ($self, $build, $dependents) = @_; my ($self, $topbuild, $dependents) = @_;
my $cfg = $self->{config}->{circleci}; my $cfg = $self->{config}->{circleci};
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : (); my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
# Figure out to which branches to send notification. # Figure out to which branches to send notification.
my %branches; my %branches;
foreach my $b ($build, @{$dependents}) { foreach my $build ($topbuild, @{$dependents}) {
my $prevBuild = getPreviousBuild($b); my $prevBuild = getPreviousBuild($build);
my $jobName = showJobName $b; my $jobName = showJobName $build;
foreach my $branch (@config) { foreach my $branch (@config) {
my $force = $branch->{force}; my $force = $branch->{force};
next unless $jobName =~ /^$branch->{jobs}$/; next unless $jobName =~ /^$branch->{jobs}$/;
# If build is failed, don't trigger circleci # If build is failed, don't trigger circleci
next if ! $force && $b->buildstatus != 0; next if ! $force && $build->buildstatus != 0;
my $fullUrl = "https://circleci.com/api/v1.1/project/" . $branch->{vcstype} . "/" . $branch->{username} . "/" . $branch->{project} . "/tree/" . $branch->{branch} . "?circle-token=" . $branch->{token}; my $fullUrl = "https://circleci.com/api/v1.1/project/" . $branch->{vcstype} . "/" . $branch->{username} . "/" . $branch->{project} . "/tree/" . $branch->{branch} . "?circle-token=" . $branch->{token};
$branches{$fullUrl} = 1; $branches{$fullUrl} = 1;

View file

@ -12,19 +12,19 @@ sub isEnabled {
} }
sub buildFinished { sub buildFinished {
my ($self, $b, $dependents) = @_; my ($self, $build, $dependents) = @_;
my $cfg = $self->{config}->{coverityscan}; my $cfg = $self->{config}->{coverityscan};
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : (); my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
# Scan the job and see if it matches any of the Coverity Scan projects # Scan the job and see if it matches any of the Coverity Scan projects
my $proj; my $proj;
my $jobName = showJobName $b; my $jobName = showJobName $build;
foreach my $p (@config) { foreach my $p (@config) {
next unless $jobName =~ /^$p->{jobs}$/; next unless $jobName =~ /^$p->{jobs}$/;
# If build is cancelled or aborted, do not upload build # If build is cancelled or aborted, do not upload build
next if $b->buildstatus == 4 || $b->buildstatus == 3; next if $build->buildstatus == 4 || $build->buildstatus == 3;
# Otherwise, select this Coverity project # Otherwise, select this Coverity project
$proj = $p; last; $proj = $p; last;
@ -47,7 +47,7 @@ sub buildFinished {
unless defined $token; unless defined $token;
# Get tarball locations # Get tarball locations
my $storePath = ($b->buildoutputs)[0]->path; my $storePath = ($build->buildoutputs)[0]->path;
my $tarballs = "$storePath/tarballs"; my $tarballs = "$storePath/tarballs";
my $covTarball; my $covTarball;
@ -87,7 +87,7 @@ sub buildFinished {
unless defined $version; unless defined $version;
# Submit build # Submit build
my $jobid = $b->id; my $jobid = $build->id;
my $desc = "Hydra Coverity Build ($jobName) - $jobid:$version"; my $desc = "Hydra Coverity Build ($jobName) - $jobid:$version";
print STDERR "uploading $desc ($shortName) to Coverity Scan\n"; print STDERR "uploading $desc ($shortName) to Coverity Scan\n";

View file

@ -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
]); ]);
} }
} }

View file

@ -29,25 +29,25 @@ sub toGiteaState {
} }
sub common { sub common {
my ($self, $build, $dependents, $status) = @_; my ($self, $topbuild, $dependents, $status) = @_;
my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000"; my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000";
# Find matching configs # Find matching configs
foreach my $b ($build, @{$dependents}) { foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $b; my $jobName = showJobName $build;
my $evals = $build->jobsetevals; my $evals = $topbuild->jobsetevals;
my $ua = LWP::UserAgent->new(); my $ua = LWP::UserAgent->new();
# Don't send out "pending/running" status updates if the build is already finished # Don't send out "pending/running" status updates if the build is already finished
next if $status < 2 && $b->finished == 1; next if $status < 2 && $build->finished == 1;
my $state = toGiteaState($status, $b->buildstatus); my $state = toGiteaState($status, $build->buildstatus);
my $body = encode_json( my $body = encode_json(
{ {
state => $state, state => $state,
target_url => "$baseurl/build/" . $b->id, target_url => "$baseurl/build/" . $build->id,
description => "Hydra build #" . $b->id . " of $jobName", description => "Hydra build #" . $build->id . " of $jobName",
context => "Hydra " . $b->get_column('job'), context => "Hydra " . $build->get_column('job'),
}); });
while (my $eval = $evals->next) { while (my $eval = $evals->next) {

View file

@ -25,32 +25,32 @@ sub toGithubState {
} }
sub common { sub common {
my ($self, $build, $dependents, $finished) = @_; my ($self, $topbuild, $dependents, $finished) = @_;
my $cfg = $self->{config}->{githubstatus}; my $cfg = $self->{config}->{githubstatus};
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : (); my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000"; my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000";
# Find matching configs # Find matching configs
foreach my $b ($build, @{$dependents}) { foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $b; my $jobName = showJobName $build;
my $evals = $build->jobsetevals; my $evals = $topbuild->jobsetevals;
my $ua = LWP::UserAgent->new(); my $ua = LWP::UserAgent->new();
foreach my $conf (@config) { foreach my $conf (@config) {
next unless $jobName =~ /^$conf->{jobs}$/; next unless $jobName =~ /^$conf->{jobs}$/;
# Don't send out "pending" status updates if the build is already finished # Don't send out "pending" status updates if the build is already finished
next if !$finished && $b->finished == 1; next if !$finished && $build->finished == 1;
my $contextTrailer = $conf->{excludeBuildFromContext} ? "" : (":" . $b->id); my $contextTrailer = $conf->{excludeBuildFromContext} ? "" : (":" . $build->id);
my $github_job_name = $jobName =~ s/-pr-\d+//r; my $github_job_name = $jobName =~ s/-pr-\d+//r;
my $extendedContext = $conf->{context} // "continuous-integration/hydra:" . $jobName . $contextTrailer; my $extendedContext = $conf->{context} // "continuous-integration/hydra:" . $jobName . $contextTrailer;
my $shortContext = $conf->{context} // "ci/hydra:" . $github_job_name . $contextTrailer; my $shortContext = $conf->{context} // "ci/hydra:" . $github_job_name . $contextTrailer;
my $context = $conf->{useShortContext} ? $shortContext : $extendedContext; my $context = $conf->{useShortContext} ? $shortContext : $extendedContext;
my $body = encode_json( my $body = encode_json(
{ {
state => $finished ? toGithubState($b->buildstatus) : "pending", state => $finished ? toGithubState($build->buildstatus) : "pending",
target_url => "$baseurl/build/" . $b->id, target_url => "$baseurl/build/" . $build->id,
description => $conf->{description} // "Hydra build #" . $b->id . " of $jobName", description => $conf->{description} // "Hydra build #" . $build->id . " of $jobName",
context => $context context => $context
}); });
my $inputs_cfg = $conf->{inputs}; my $inputs_cfg = $conf->{inputs};

View file

@ -37,25 +37,25 @@ sub toGitlabState {
} }
sub common { sub common {
my ($self, $build, $dependents, $status) = @_; my ($self, $topbuild, $dependents, $status) = @_;
my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000"; my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000";
# Find matching configs # Find matching configs
foreach my $b ($build, @{$dependents}) { foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $b; my $jobName = showJobName $build;
my $evals = $build->jobsetevals; my $evals = $topbuild->jobsetevals;
my $ua = LWP::UserAgent->new(); my $ua = LWP::UserAgent->new();
# Don't send out "pending/running" status updates if the build is already finished # Don't send out "pending/running" status updates if the build is already finished
next if $status < 2 && $b->finished == 1; next if $status < 2 && $build->finished == 1;
my $state = toGitlabState($status, $b->buildstatus); my $state = toGitlabState($status, $build->buildstatus);
my $body = encode_json( my $body = encode_json(
{ {
state => $state, state => $state,
target_url => "$baseurl/build/" . $b->id, target_url => "$baseurl/build/" . $build->id,
description => "Hydra build #" . $b->id . " of $jobName", description => "Hydra build #" . $build->id . " of $jobName",
name => "Hydra " . $b->get_column('job'), name => "Hydra " . $build->get_column('job'),
}); });
while (my $eval = $evals->next) { while (my $eval = $evals->next) {
my $gitlabstatusInput = $eval->jobsetevalinputs->find({ name => "gitlab_status_repo" }); my $gitlabstatusInput = $eval->jobsetevalinputs->find({ name => "gitlab_status_repo" });

View file

@ -11,7 +11,7 @@ sub isEnabled {
} }
sub buildFinished { sub buildFinished {
my ($self, $build, $dependents) = @_; my ($self, $topbuild, $dependents) = @_;
my $cfg = $self->{config}->{hipchat}; my $cfg = $self->{config}->{hipchat};
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : (); my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
@ -21,46 +21,46 @@ sub buildFinished {
# Figure out to which rooms to send notification. For each email # Figure out to which rooms to send notification. For each email
# room, we send one aggregate message. # room, we send one aggregate message.
my %rooms; my %rooms;
foreach my $b ($build, @{$dependents}) { foreach my $build ($topbuild, @{$dependents}) {
my $prevBuild = getPreviousBuild($b); my $prevBuild = getPreviousBuild($build);
my $jobName = showJobName $b; my $jobName = showJobName $build;
foreach my $room (@config) { foreach my $room (@config) {
my $force = $room->{force}; my $force = $room->{force};
next unless $jobName =~ /^$room->{jobs}$/; next unless $jobName =~ /^$room->{jobs}$/;
# If build is cancelled or aborted, do not send email. # If build is cancelled or aborted, do not send email.
next if ! $force && ($b->buildstatus == 4 || $b->buildstatus == 3); next if ! $force && ($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 ! $force && defined $prevBuild && ($b->buildstatus == $prevBuild->buildstatus); next if ! $force && defined $prevBuild && ($build->buildstatus == $prevBuild->buildstatus);
$rooms{$room->{room}} //= { room => $room, builds => [] }; $rooms{$room->{room}} //= { room => $room, builds => [] };
push @{$rooms{$room->{room}}->{builds}}, $b; push @{$rooms{$room->{room}}->{builds}}, $build;
} }
} }
return if scalar keys %rooms == 0; return if scalar keys %rooms == 0;
my ($authors, $nrCommits) = getResponsibleAuthors($build, $self->{plugins}); my ($authors, $nrCommits) = getResponsibleAuthors($topbuild, $self->{plugins});
# Send a message to each room. # Send a message to each room.
foreach my $roomId (keys %rooms) { foreach my $roomId (keys %rooms) {
my $room = $rooms{$roomId}; my $room = $rooms{$roomId};
my @deps = grep { $_->id != $build->id } @{$room->{builds}}; my @deps = grep { $_->id != $topbuild->id } @{$room->{builds}};
my $img = my $img =
$build->buildstatus == 0 ? "$baseurl/static/images/checkmark_16.png" : $topbuild->buildstatus == 0 ? "$baseurl/static/images/checkmark_16.png" :
$build->buildstatus == 2 ? "$baseurl/static/images/dependency_16.png" : $topbuild->buildstatus == 2 ? "$baseurl/static/images/dependency_16.png" :
$build->buildstatus == 4 ? "$baseurl/static/images/cancelled_16.png" : $topbuild->buildstatus == 4 ? "$baseurl/static/images/cancelled_16.png" :
"$baseurl/static/images/error_16.png"; "$baseurl/static/images/error_16.png";
my $msg = ""; my $msg = "";
$msg .= "<img src='$img'/> "; $msg .= "<img src='$img'/> ";
$msg .= "Job <a href='$baseurl/job/${\$build->get_column('project')}/${\$build->get_column('jobset')}/${\$build->get_column('job')}'>${\showJobName($build)}</a>"; $msg .= "Job <a href='$baseurl/job/${\$topbuild->get_column('project')}/${\$topbuild->get_column('jobset')}/${\$topbuild->get_column('job')}'>${\showJobName($topbuild)}</a>";
$msg .= " (and ${\scalar @deps} others)" if scalar @deps > 0; $msg .= " (and ${\scalar @deps} others)" if scalar @deps > 0;
$msg .= ": <a href='$baseurl/build/${\$build->id}'>" . showStatus($build) . "</a>"; $msg .= ": <a href='$baseurl/build/${\$topbuild->id}'>" . showStatus($topbuild) . "</a>";
if (scalar keys %{$authors} > 0) { if (scalar keys %{$authors} > 0) {
# FIXME: HTML escaping # FIXME: HTML escaping
@ -79,7 +79,7 @@ sub buildFinished {
message => $msg, message => $msg,
message_format => 'html', message_format => 'html',
notify => $room->{room}->{notify} || 0, notify => $room->{room}->{notify} || 0,
color => $build->buildstatus == 0 ? 'green' : 'red' }); color => $topbuild->buildstatus == 0 ? 'green' : 'red' });
print STDERR $resp->status_line, ": ", $resp->decoded_content,"\n" if !$resp->is_success; print STDERR $resp->status_line, ": ", $resp->decoded_content,"\n" if !$resp->is_success;
} }

View file

@ -77,7 +77,7 @@ sub renderDuration {
} }
sub buildFinished { sub buildFinished {
my ($self, $build, $dependents) = @_; my ($self, $topbuild, $dependents) = @_;
my $cfg = $self->{config}->{slack}; my $cfg = $self->{config}->{slack};
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : (); my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
@ -86,12 +86,12 @@ sub buildFinished {
# Figure out to which channelss to send notification. For each channel # Figure out to which channelss to send notification. For each channel
# we send one aggregate message. # we send one aggregate message.
my %channels; my %channels;
foreach my $b ($build, @{$dependents}) { foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $b; my $jobName = showJobName $build;
my $buildStatus = $b->buildstatus; my $buildStatus = $build->buildstatus;
my $cancelledOrAborted = $buildStatus == 4 || $buildStatus == 3; my $cancelledOrAborted = $buildStatus == 4 || $buildStatus == 3;
my $prevBuild = getPreviousBuild($b); my $prevBuild = getPreviousBuild($build);
my $sameAsPrevious = defined $prevBuild && ($buildStatus == $prevBuild->buildstatus); my $sameAsPrevious = defined $prevBuild && ($buildStatus == $prevBuild->buildstatus);
my $prevBuildStatus = (defined $prevBuild) ? $prevBuild->buildstatus : -1; my $prevBuildStatus = (defined $prevBuild) ? $prevBuild->buildstatus : -1;
my $prevBuildId = (defined $prevBuild) ? $prevBuild->id : -1; my $prevBuildId = (defined $prevBuild) ? $prevBuild->id : -1;
@ -114,34 +114,34 @@ sub buildFinished {
print STDERR "SlackNotification_Debug adding $jobName to the report list\n"; print STDERR "SlackNotification_Debug adding $jobName to the report list\n";
$channels{$channel->{url}} //= { channel => $channel, builds => [] }; $channels{$channel->{url}} //= { channel => $channel, builds => [] };
push @{$channels{$channel->{url}}->{builds}}, $b; push @{$channels{$channel->{url}}->{builds}}, $build;
} }
} }
return if scalar keys %channels == 0; return if scalar keys %channels == 0;
my ($authors, $nrCommits) = getResponsibleAuthors($build, $self->{plugins}); my ($authors, $nrCommits) = getResponsibleAuthors($topbuild, $self->{plugins});
# Send a message to each room. # Send a message to each room.
foreach my $url (keys %channels) { foreach my $url (keys %channels) {
my $channel = $channels{$url}; my $channel = $channels{$url};
my @deps = grep { $_->id != $build->id } @{$channel->{builds}}; my @deps = grep { $_->id != $topbuild->id } @{$channel->{builds}};
my $img = my $img =
$build->buildstatus == 0 ? "$baseurl/static/images/checkmark_256.png" : $topbuild->buildstatus == 0 ? "$baseurl/static/images/checkmark_256.png" :
$build->buildstatus == 2 ? "$baseurl/static/images/dependency_256.png" : $topbuild->buildstatus == 2 ? "$baseurl/static/images/dependency_256.png" :
$build->buildstatus == 4 ? "$baseurl/static/images/cancelled_256.png" : $topbuild->buildstatus == 4 ? "$baseurl/static/images/cancelled_256.png" :
"$baseurl/static/images/error_256.png"; "$baseurl/static/images/error_256.png";
my $color = my $color =
$build->buildstatus == 0 ? "good" : $topbuild->buildstatus == 0 ? "good" :
$build->buildstatus == 4 ? "warning" : $topbuild->buildstatus == 4 ? "warning" :
"danger"; "danger";
my $text = ""; my $text = "";
$text .= "Job <$baseurl/job/${\$build->get_column('project')}/${\$build->get_column('jobset')}/${\$build->get_column('job')}|${\showJobName($build)}>"; $text .= "Job <$baseurl/job/${\$topbuild->get_column('project')}/${\$topbuild->get_column('jobset')}/${\$topbuild->get_column('job')}|${\showJobName($topbuild)}>";
$text .= " (and ${\scalar @deps} others)" if scalar @deps > 0; $text .= " (and ${\scalar @deps} others)" if scalar @deps > 0;
$text .= ": <$baseurl/build/${\$build->id}|" . showStatus($build) . ">". " in " . renderDuration($build); $text .= ": <$baseurl/build/${\$topbuild->id}|" . showStatus($topbuild) . ">". " in " . renderDuration($topbuild);
if (scalar keys %{$authors} > 0) { if (scalar keys %{$authors} > 0) {
# FIXME: escaping # FIXME: escaping
@ -155,12 +155,12 @@ sub buildFinished {
my $msg = my $msg =
{ attachments => { attachments =>
[{ fallback => "Job " . showJobName($build) . " build number " . $build->id . ": " . showStatus($build), [{ fallback => "Job " . showJobName($topbuild) . " build number " . $topbuild->id . ": " . showStatus($topbuild),
text => $text, text => $text,
thumb_url => $img, thumb_url => $img,
color => $color, color => $color,
title => "Job " . showJobName($build) . " build number " . $build->id, title => "Job " . showJobName($topbuild) . " build number " . $topbuild->id,
title_link => "$baseurl/build/${\$build->id}" title_link => "$baseurl/build/${\$topbuild->id}"
}] }]
}; };