Refactor code
Extract the conditions before the loop, as they do not change due to channel definition.
This commit is contained in:
parent
956f009672
commit
986fde8888
|
@ -87,20 +87,24 @@ sub buildFinished {
|
||||||
# we send one aggregate message.
|
# we send one aggregate message.
|
||||||
my %channels;
|
my %channels;
|
||||||
foreach my $b ($build, @{$dependents}) {
|
foreach my $b ($build, @{$dependents}) {
|
||||||
my $prevBuild = getPreviousBuild($b);
|
|
||||||
my $jobName = showJobName $b;
|
my $jobName = showJobName $b;
|
||||||
|
my $buildStatus = $b->buildstatus;
|
||||||
|
my $cancelledOrAborted = $buildStatus == 4 || $buildStatus == 3;
|
||||||
|
|
||||||
|
my $prevBuild = getPreviousBuild($b);
|
||||||
|
my $sameAsPrevious = defined $prevBuild && ($buildStatus == $prevBuild->buildstatus);
|
||||||
|
|
||||||
foreach my $channel (@config) {
|
foreach my $channel (@config) {
|
||||||
next unless $jobName =~ /^$channel->{jobs}$/;
|
next unless $jobName =~ /^$channel->{jobs}$/;
|
||||||
|
|
||||||
my $force = $channel->{force};
|
my $force = $channel->{force};
|
||||||
|
|
||||||
# If build is cancelled or aborted, do not send email.
|
# If build is cancelled or aborted, do not send Slack notification.
|
||||||
next if ! $force && ($b->buildstatus == 4 || $b->buildstatus == 3);
|
next if ! $force && $cancelledOrAborted;
|
||||||
|
|
||||||
# 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 Slack notification.
|
||||||
next if ! $force && defined $prevBuild && ($b->buildstatus == $prevBuild->buildstatus);
|
next if ! $force && $sameAsPrevious;
|
||||||
|
|
||||||
$channels{$channel->{url}} //= { channel => $channel, builds => [] };
|
$channels{$channel->{url}} //= { channel => $channel, builds => [] };
|
||||||
push @{$channels{$channel->{url}}->{builds}}, $b;
|
push @{$channels{$channel->{url}}->{builds}}, $b;
|
||||||
|
|
Loading…
Reference in a new issue