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 %constituentJobs;
foreach my $b (@constituents) {
$aggregates->{$b->get_column('aggregate')}->{constituents}->{$b->job} =
{ id => $b->id, finished => $b->finished, buildstatus => $b->buildstatus };
$constituentJobs{$b->job} = 1;
foreach my $build (@constituents) {
$aggregates->{$build->get_column('aggregate')}->{constituents}->{$build->job} =
{ id => $build->id, finished => $build->finished, buildstatus => $build->buildstatus };
$constituentJobs{$build->job} = 1;
}
foreach my $agg (keys %$aggregates) {

View file

@ -64,9 +64,9 @@ sub view_GET {
$c->stash->{otherEval} = $eval2 if defined $eval2;
sub cmpBuilds {
my ($a, $b) = @_;
return $a->get_column('job') cmp $b->get_column('job')
|| $a->get_column('system') cmp $b->get_column('system')
my ($left, $right) = @_;
return $left->get_column('job') cmp $right->get_column('job')
|| $left->get_column('system') cmp $right->get_column('system')
}
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
# until hydra-notify is started, as buildFinished is never emitted for them.
foreach my $b ($self->{"build"}, @{$self->{"dependents"}}) {
if ($b->finished && defined($b->notificationpendingsince)) {
$b->update({ notificationpendingsince => undef })
foreach my $build ($self->{"build"}, @{$self->{"dependents"}}) {
if ($build->finished && defined($build->notificationpendingsince)) {
$build->update({ notificationpendingsince => undef })
}
}

View file

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

View file

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

View file

@ -13,22 +13,22 @@ sub isEnabled {
}
sub buildFinished {
my ($self, $build, $dependents) = @_;
my ($self, $topbuild, $dependents) = @_;
my $cfg = $self->{config}->{circleci};
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
# Figure out to which branches to send notification.
my %branches;
foreach my $b ($build, @{$dependents}) {
my $prevBuild = getPreviousBuild($b);
my $jobName = showJobName $b;
foreach my $build ($topbuild, @{$dependents}) {
my $prevBuild = getPreviousBuild($build);
my $jobName = showJobName $build;
foreach my $branch (@config) {
my $force = $branch->{force};
next unless $jobName =~ /^$branch->{jobs}$/;
# 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};
$branches{$fullUrl} = 1;

View file

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

View file

@ -46,46 +46,46 @@ EOF
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
# each email address, we send one aggregate email listing only the
# relevant builds for that address.
my %addresses;
foreach my $b ($build, @{$dependents}) {
my $prevBuild = getPreviousBuild($b);
foreach my $build ($topbuild, @{$dependents}) {
my $prevBuild = getPreviousBuild($build);
# Do we want to send mail for this build?
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.
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
# 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 // "")) {
$address = trim $address;
$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 $prevBuild = getPreviousBuild($build);
my $prevBuild = getPreviousBuild($topbuild);
if (scalar keys %{$authors} > 0 &&
((!defined $prevBuild) || ($build->buildstatus != $prevBuild->buildstatus))) {
((!defined $prevBuild) || ($topbuild->buildstatus != $prevBuild->buildstatus))) {
my @x = map { "$_ <$authors->{$_}>" } (sort keys %{$authors});
$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.
@ -96,11 +96,11 @@ sub buildFinished {
my $tt = Template->new({});
my $vars =
{ build => $build, prevBuild => getPreviousBuild($build)
, dependents => [grep { $_->id != $build->id } @builds]
{ build => $topbuild, prevBuild => getPreviousBuild($topbuild)
, dependents => [grep { $_->id != $topbuild->id } @builds]
, baseurl => getBaseUrl($self->{config})
, showJobName => \&showJobName, showStatus => \&showStatus
, showSystem => index($build->get_column('job'), $build->system) == -1
, showSystem => index($topbuild->get_column('job'), $topbuild->system) == -1
, nrCommits => $nrCommits
, authorList => $authorList
};
@ -113,16 +113,16 @@ sub buildFinished {
$body =~ s/[\ ]+$//gm;
my $subject =
showStatus($build) . ": Hydra job " . showJobName($build)
. ($vars->{showSystem} ? " on " . $build->system : "")
showStatus($topbuild) . ": Hydra job " . showJobName($topbuild)
. ($vars->{showSystem} ? " on " . $topbuild->system : "")
. (scalar @{$vars->{dependents}} > 0 ? " (and " . scalar @{$vars->{dependents}} . " others)" : "");
sendEmail(
$self->{config}, $to, $subject, $body,
[ 'X-Hydra-Project' => $build->get_column('project'),
, 'X-Hydra-Jobset' => $build->get_column('jobset'),
, 'X-Hydra-Job' => $build->get_column('job'),
, 'X-Hydra-System' => $build->system
[ 'X-Hydra-Project' => $topbuild->get_column('project'),
, 'X-Hydra-Jobset' => $topbuild->get_column('jobset'),
, 'X-Hydra-Job' => $topbuild->get_column('job'),
, 'X-Hydra-System' => $topbuild->system
]);
}
}

View file

@ -29,25 +29,25 @@ sub toGiteaState {
}
sub common {
my ($self, $build, $dependents, $status) = @_;
my ($self, $topbuild, $dependents, $status) = @_;
my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000";
# Find matching configs
foreach my $b ($build, @{$dependents}) {
my $jobName = showJobName $b;
my $evals = $build->jobsetevals;
foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $build;
my $evals = $topbuild->jobsetevals;
my $ua = LWP::UserAgent->new();
# 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(
{
state => $state,
target_url => "$baseurl/build/" . $b->id,
description => "Hydra build #" . $b->id . " of $jobName",
context => "Hydra " . $b->get_column('job'),
target_url => "$baseurl/build/" . $build->id,
description => "Hydra build #" . $build->id . " of $jobName",
context => "Hydra " . $build->get_column('job'),
});
while (my $eval = $evals->next) {

View file

@ -25,32 +25,32 @@ sub toGithubState {
}
sub common {
my ($self, $build, $dependents, $finished) = @_;
my ($self, $topbuild, $dependents, $finished) = @_;
my $cfg = $self->{config}->{githubstatus};
my @config = defined $cfg ? ref $cfg eq "ARRAY" ? @$cfg : ($cfg) : ();
my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000";
# Find matching configs
foreach my $b ($build, @{$dependents}) {
my $jobName = showJobName $b;
my $evals = $build->jobsetevals;
foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $build;
my $evals = $topbuild->jobsetevals;
my $ua = LWP::UserAgent->new();
foreach my $conf (@config) {
next unless $jobName =~ /^$conf->{jobs}$/;
# 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 $extendedContext = $conf->{context} // "continuous-integration/hydra:" . $jobName . $contextTrailer;
my $shortContext = $conf->{context} // "ci/hydra:" . $github_job_name . $contextTrailer;
my $context = $conf->{useShortContext} ? $shortContext : $extendedContext;
my $body = encode_json(
{
state => $finished ? toGithubState($b->buildstatus) : "pending",
target_url => "$baseurl/build/" . $b->id,
description => $conf->{description} // "Hydra build #" . $b->id . " of $jobName",
state => $finished ? toGithubState($build->buildstatus) : "pending",
target_url => "$baseurl/build/" . $build->id,
description => $conf->{description} // "Hydra build #" . $build->id . " of $jobName",
context => $context
});
my $inputs_cfg = $conf->{inputs};

View file

@ -37,25 +37,25 @@ sub toGitlabState {
}
sub common {
my ($self, $build, $dependents, $status) = @_;
my ($self, $topbuild, $dependents, $status) = @_;
my $baseurl = $self->{config}->{'base_uri'} || "http://localhost:3000";
# Find matching configs
foreach my $b ($build, @{$dependents}) {
my $jobName = showJobName $b;
my $evals = $build->jobsetevals;
foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $build;
my $evals = $topbuild->jobsetevals;
my $ua = LWP::UserAgent->new();
# 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(
{
state => $state,
target_url => "$baseurl/build/" . $b->id,
description => "Hydra build #" . $b->id . " of $jobName",
name => "Hydra " . $b->get_column('job'),
target_url => "$baseurl/build/" . $build->id,
description => "Hydra build #" . $build->id . " of $jobName",
name => "Hydra " . $build->get_column('job'),
});
while (my $eval = $evals->next) {
my $gitlabstatusInput = $eval->jobsetevalinputs->find({ name => "gitlab_status_repo" });

View file

@ -11,7 +11,7 @@ sub isEnabled {
}
sub buildFinished {
my ($self, $build, $dependents) = @_;
my ($self, $topbuild, $dependents) = @_;
my $cfg = $self->{config}->{hipchat};
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
# room, we send one aggregate message.
my %rooms;
foreach my $b ($build, @{$dependents}) {
my $prevBuild = getPreviousBuild($b);
my $jobName = showJobName $b;
foreach my $build ($topbuild, @{$dependents}) {
my $prevBuild = getPreviousBuild($build);
my $jobName = showJobName $build;
foreach my $room (@config) {
my $force = $room->{force};
next unless $jobName =~ /^$room->{jobs}$/;
# 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
# 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 => [] };
push @{$rooms{$room->{room}}->{builds}}, $b;
push @{$rooms{$room->{room}}->{builds}}, $build;
}
}
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.
foreach my $roomId (keys %rooms) {
my $room = $rooms{$roomId};
my @deps = grep { $_->id != $build->id } @{$room->{builds}};
my @deps = grep { $_->id != $topbuild->id } @{$room->{builds}};
my $img =
$build->buildstatus == 0 ? "$baseurl/static/images/checkmark_16.png" :
$build->buildstatus == 2 ? "$baseurl/static/images/dependency_16.png" :
$build->buildstatus == 4 ? "$baseurl/static/images/cancelled_16.png" :
$topbuild->buildstatus == 0 ? "$baseurl/static/images/checkmark_16.png" :
$topbuild->buildstatus == 2 ? "$baseurl/static/images/dependency_16.png" :
$topbuild->buildstatus == 4 ? "$baseurl/static/images/cancelled_16.png" :
"$baseurl/static/images/error_16.png";
my $msg = "";
$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 .= ": <a href='$baseurl/build/${\$build->id}'>" . showStatus($build) . "</a>";
$msg .= ": <a href='$baseurl/build/${\$topbuild->id}'>" . showStatus($topbuild) . "</a>";
if (scalar keys %{$authors} > 0) {
# FIXME: HTML escaping
@ -79,7 +79,7 @@ sub buildFinished {
message => $msg,
message_format => 'html',
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;
}

View file

@ -77,7 +77,7 @@ sub renderDuration {
}
sub buildFinished {
my ($self, $build, $dependents) = @_;
my ($self, $topbuild, $dependents) = @_;
my $cfg = $self->{config}->{slack};
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
# we send one aggregate message.
my %channels;
foreach my $b ($build, @{$dependents}) {
my $jobName = showJobName $b;
my $buildStatus = $b->buildstatus;
foreach my $build ($topbuild, @{$dependents}) {
my $jobName = showJobName $build;
my $buildStatus = $build->buildstatus;
my $cancelledOrAborted = $buildStatus == 4 || $buildStatus == 3;
my $prevBuild = getPreviousBuild($b);
my $prevBuild = getPreviousBuild($build);
my $sameAsPrevious = defined $prevBuild && ($buildStatus == $prevBuild->buildstatus);
my $prevBuildStatus = (defined $prevBuild) ? $prevBuild->buildstatus : -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";
$channels{$channel->{url}} //= { channel => $channel, builds => [] };
push @{$channels{$channel->{url}}->{builds}}, $b;
push @{$channels{$channel->{url}}->{builds}}, $build;
}
}
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.
foreach my $url (keys %channels) {
my $channel = $channels{$url};
my @deps = grep { $_->id != $build->id } @{$channel->{builds}};
my @deps = grep { $_->id != $topbuild->id } @{$channel->{builds}};
my $img =
$build->buildstatus == 0 ? "$baseurl/static/images/checkmark_256.png" :
$build->buildstatus == 2 ? "$baseurl/static/images/dependency_256.png" :
$build->buildstatus == 4 ? "$baseurl/static/images/cancelled_256.png" :
$topbuild->buildstatus == 0 ? "$baseurl/static/images/checkmark_256.png" :
$topbuild->buildstatus == 2 ? "$baseurl/static/images/dependency_256.png" :
$topbuild->buildstatus == 4 ? "$baseurl/static/images/cancelled_256.png" :
"$baseurl/static/images/error_256.png";
my $color =
$build->buildstatus == 0 ? "good" :
$build->buildstatus == 4 ? "warning" :
$topbuild->buildstatus == 0 ? "good" :
$topbuild->buildstatus == 4 ? "warning" :
"danger";
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 .= ": <$baseurl/build/${\$build->id}|" . showStatus($build) . ">". " in " . renderDuration($build);
$text .= ": <$baseurl/build/${\$topbuild->id}|" . showStatus($topbuild) . ">". " in " . renderDuration($topbuild);
if (scalar keys %{$authors} > 0) {
# FIXME: escaping
@ -155,12 +155,12 @@ sub buildFinished {
my $msg =
{ attachments =>
[{ fallback => "Job " . showJobName($build) . " build number " . $build->id . ": " . showStatus($build),
[{ fallback => "Job " . showJobName($topbuild) . " build number " . $topbuild->id . ": " . showStatus($topbuild),
text => $text,
thumb_url => $img,
color => $color,
title => "Job " . showJobName($build) . " build number " . $build->id,
title_link => "$baseurl/build/${\$build->id}"
title => "Job " . showJobName($topbuild) . " build number " . $topbuild->id,
title_link => "$baseurl/build/${\$topbuild->id}"
}]
};