From 1349887974922b24e63d1bae548d4b02e7f0ff0b Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 10 Jan 2022 11:40:23 -0800 Subject: [PATCH] BuildDiff: split out from JobsetEval GET impl --- src/lib/Hydra/Controller/JobsetEval.pm | 51 +---------------- src/lib/Hydra/Helper/BuildDiff.pm | 76 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 49 deletions(-) create mode 100644 src/lib/Hydra/Helper/BuildDiff.pm diff --git a/src/lib/Hydra/Controller/JobsetEval.pm b/src/lib/Hydra/Controller/JobsetEval.pm index ed0fe12e..17b14ae1 100644 --- a/src/lib/Hydra/Controller/JobsetEval.pm +++ b/src/lib/Hydra/Controller/JobsetEval.pm @@ -6,6 +6,7 @@ use warnings; use base 'Hydra::Base::Controller::NixChannel'; use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; +use Hydra::Helper::BuildDiff; use List::SomeUtils qw(uniq); @@ -75,55 +76,7 @@ sub view_GET { @builds = sort { cmpBuilds($a, $b) } @builds; @builds2 = sort { cmpBuilds($a, $b) } @builds2; - $c->stash->{stillSucceed} = []; - $c->stash->{stillFail} = []; - $c->stash->{nowSucceed} = []; - $c->stash->{nowFail} = []; - $c->stash->{new} = []; - $c->stash->{removed} = []; - $c->stash->{unfinished} = []; - $c->stash->{aborted} = []; - $c->stash->{failed} = []; - - my $n = 0; - foreach my $build (@builds) { - my $aborted = $build->finished != 0 && ($build->buildstatus == 3 || $build->buildstatus == 4); - my $d; - my $found = 0; - while ($n < scalar(@builds2)) { - my $build2 = $builds2[$n]; - my $d = cmpBuilds($build, $build2); - last if $d == -1; - if ($d == 0) { - $n++; - $found = 1; - if ($aborted) { - # do nothing - } elsif ($build->finished == 0 || $build2->finished == 0) { - push @{$c->stash->{unfinished}}, $build; - } elsif ($build->buildstatus == 0 && $build2->buildstatus == 0) { - push @{$c->stash->{stillSucceed}}, $build; - } elsif ($build->buildstatus != 0 && $build2->buildstatus != 0) { - push @{$c->stash->{stillFail}}, $build; - } elsif ($build->buildstatus == 0 && $build2->buildstatus != 0) { - push @{$c->stash->{nowSucceed}}, $build; - } elsif ($build->buildstatus != 0 && $build2->buildstatus == 0) { - push @{$c->stash->{nowFail}}, $build; - } else { die; } - last; - } - push @{$c->stash->{removed}}, { job => $build2->get_column('job'), system => $build2->get_column('system') }; - $n++; - } - if ($aborted) { - push @{$c->stash->{aborted}}, $build; - } else { - push @{$c->stash->{new}}, $build if !$found; - } - if ($build->buildstatus != 0) { - push @{$c->stash->{failed}}, $build; - } - } + buildDiff(@builds, @builds2); $c->stash->{full} = ($c->req->params->{full} || "0") eq "1"; diff --git a/src/lib/Hydra/Helper/BuildDiff.pm b/src/lib/Hydra/Helper/BuildDiff.pm new file mode 100644 index 00000000..7655bf4d --- /dev/null +++ b/src/lib/Hydra/Helper/BuildDiff.pm @@ -0,0 +1,76 @@ +package Hydra::Helper::BuildDiff; + +use utf8; +use strict; +use warnings; +use base 'Hydra::Base::Controller::NixChannel'; +use Hydra::Helper::Nix; +use Hydra::Helper::CatalystUtils; +use List::SomeUtils qw(uniq); + +our @ISA = qw(Exporter); +our @EXPORT = qw( + buildDiff +); + +use Data::Dumper; + +sub buildDiff { + my ($builds, $builds2) = @_; + + my $ret = [ + stillSucceed => [], + stillFail => [], + nowSucceed => [], + nowFail => [], + new => [], + removed => [], + unfinished => [], + aborted => [], + failed => [], + ]; + + my $n = 0; + foreach my $build (@{$builds}) { + my $aborted = $build->finished != 0 && ($build->buildstatus == 3 || $build->buildstatus == 4); + my $d; + my $found = 0; + while ($n < scalar($builds2)) { + my $build2 = @{$builds2}[$n]; + my $d = cmpBuilds($build, $build2); + last if $d == -1; + if ($d == 0) { + $n++; + $found = 1; + if ($aborted) { + # do nothing + } elsif ($build->finished == 0 || $build2->finished == 0) { + push @{$ret->{unfinished}}, $build; + } elsif ($build->buildstatus == 0 && $build2->buildstatus == 0) { + push @{$ret->{stillSucceed}}, $build; + } elsif ($build->buildstatus != 0 && $build2->buildstatus != 0) { + push @{$ret->{stillFail}}, $build; + } elsif ($build->buildstatus == 0 && $build2->buildstatus != 0) { + push @{$ret->{nowSucceed}}, $build; + } elsif ($build->buildstatus != 0 && $build2->buildstatus == 0) { + push @{$ret->{nowFail}}, $build; + } else { die; } + last; + } + push @{$ret->{removed}}, { job => $build2->get_column('job'), system => $build2->get_column('system') }; + $n++; + } + if ($aborted) { + push @{$ret->{aborted}}, $build; + } else { + push @{$ret->{new}}, $build if !$found; + } + if ($build->buildstatus != 0) { + push @{$ret->{failed}}, $build; + } + } + + return $ret; +} + +1; \ No newline at end of file