Skip to content

Commit 4760f8c

Browse files
committed
Implement build version sorting by oldest job in build
1 parent 5fc353a commit 4760f8c

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/OpenQA/BuildResults.pm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package OpenQA::BuildResults;
66
use Mojo::Base -strict, -signatures;
77

88
use OpenQA::Jobs::Constants;
9+
use OpenQA::Constants qw(BUILD_SORT_BY_NAME BUILD_SORT_BY_NEWEST_JOB BUILD_SORT_BY_OLDEST_JOB);
910
use OpenQA::Schema::Result::Jobs;
1011
use OpenQA::Utils;
1112
use OpenQA::Log qw(log_error);
@@ -131,13 +132,18 @@ sub compute_build_results ($group, $limit, $time_limit_days, $tags, $subgroup_fi
131132
return \%result;
132133
}
133134

135+
# build sorting
136+
my $buildver_sort_mode = BUILD_SORT_BY_NAME;
137+
$buildver_sort_mode = $group->build_version_sort if $group->can('build_version_sort');
138+
my $sort_column = $buildver_sort_mode == BUILD_SORT_BY_OLDEST_JOB ? 'oldest_job' : 'newest_job';
139+
134140
# 400 is the max. limit selectable in the group overview
135141
my $row_limit = (defined($limit) && $limit > 400) ? $limit : 400;
136142
my @search_cols = qw(VERSION BUILD);
137143
my %search_opts = (
138-
select => [@search_cols, {max => 'id', -as => 'lasted_job'}],
144+
select => [@search_cols, {max => 'id', -as => 'newest_job'}, {min => 'id', -as => 'oldest_job'}],
139145
group_by => \@search_cols,
140-
order_by => {-desc => 'lasted_job'},
146+
order_by => {-desc => $sort_column},
141147
rows => $row_limit
142148
);
143149
my %search_filter = (group_id => {in => $group_ids});
@@ -169,12 +175,7 @@ sub compute_build_results ($group, $limit, $time_limit_days, $tags, $subgroup_fi
169175
$build->{key} = join('-', $version, $buildnr);
170176
$versions_per_build{$buildnr}->{$version} = 1;
171177
}
172-
# sort by treating the key as a version number, if job group
173-
# indicates this is OK (the default). otherwise, list remains
174-
# sorted on the most recent job for each build
175-
my $versort = 1;
176-
$versort = $group->build_version_sort if $group->can('build_version_sort');
177-
if ($versort) {
178+
if ($buildver_sort_mode == BUILD_SORT_BY_NAME) {
178179
@builds = reverse sort { versioncmp($a->{key}, $b->{key}); } @builds;
179180
}
180181

t/22-dashboard.t

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use Test::MockModule;
1414
use OpenQA::Test::Case;
1515
use OpenQA::Test::TimeLimit '10';
1616
use OpenQA::Jobs::Constants;
17+
use OpenQA::Constants qw(BUILD_SORT_BY_NEWEST_JOB BUILD_SORT_BY_OLDEST_JOB);
1718
use OpenQA::Utils qw(regex_match);
1819
use Mojo::File qw(tempfile);
1920

@@ -498,9 +499,14 @@ subtest 'proper build sorting for dotted build number' => sub {
498499

499500
# without version sorting, builds should be sorted in reverse order
500501
# (as the build which most recently had a job created sorts first)
501-
$group->update({build_version_sort => 0});
502+
$group->update({build_version_sort => BUILD_SORT_BY_NEWEST_JOB});
502503
@build_names = reverse @build_names;
503504
check_builds(\@build_names, $group, 'builds shown sorted by dotted number');
505+
506+
# sorted by oldest job per build (which is the same here as there is no overlap)
507+
$group->update({build_version_sort => BUILD_SORT_BY_OLDEST_JOB});
508+
check_builds(\@build_names, $group, 'builds shown sorted by dotted number');
509+
504510
};
505511

506512
subtest 'job groups with multiple version and builds' => sub {

0 commit comments

Comments
 (0)