Skip to content

Commit

Permalink
WIP Allow excluding groupless jobs through filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richardson committed Aug 6, 2024
1 parent 40fce5a commit 006b06c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/OpenQA/WebAPI/Controller/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,26 @@ sub _prepare_groupids ($self) {
$v->optional('groupid')->num(0, undef);
return $v->is_valid('groupid') ? $self->every_param('groupid') : undef;
}
# lib/OpenQA/WebAPI/Controller/Test.pm

sub _prepare_groupids ($self) {
my $v = $self->validation;
$v->optional('groupid')->num(0, undef);
$v->optional('not_groupid')->num(0, undef); # Add validation for not_groupid

my $groupids = $v->is_valid('groupid') ? $self->every_param('groupid') : [];
my $not_groupids = $v->is_valid('not_groupid') ? $self->every_param('not_groupid') : [];

if (@$not_groupids) {
my %not_groupid_hash = map { $_ => 1 } @$not_groupids;
$groupids = [grep { !$not_groupid_hash{$_} } @$groupids];
}

return $groupids if @$groupids;
return [0] unless my $groups = $self->groups_for_globs;
return [map { $_->id } @$groups];
}


# avoid running a SELECT for each job
sub _fetch_failed_modules_by_jobs ($self, $ids) {
Expand Down
11 changes: 11 additions & 0 deletions lib/OpenQA/WebAPI/Plugin/Helpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ sub _compose_job_overview_search_args ($c) {
$v->optional($_, 'not_empty') for JOBS_OVERVIEW_SEARCH_CRITERIA;
$v->optional('comment');
$v->optional('groupid')->num(0, undef);
$v->optional('not_groupid')->num(0, undef);
$v->optional('modules', 'comma_separated');
$v->optional('limit', 'not_empty')->num(0, undef);

Expand Down Expand Up @@ -480,6 +481,16 @@ sub _compose_job_overview_search_args ($c) {
# allow filtering by group ID or group name
$search_args{groupids} = [map { $_->id } @groups] if @groups;

# allow excluding jobs by group ID (0 to exclude groupless jobs)
if ($v->is_valid('not_groupid')) {
my @not_group_ids = @{$v->every_param('not_groupid')};
$search_args{groupid} = {-not_in => \@not_group_ids};
if (grep { $_ == 0 } @not_group_ids) {
# Exclude jobs not belonging to any group
$search_args{groupid} = {-not_in => \@not_group_ids, '!=' => undef};
}
}

# allow filtering by comment text
if (my $c = $v->param('comment')) { $search_args{comment_text} = $c }

Expand Down

0 comments on commit 006b06c

Please sign in to comment.