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 0b3a25e commit 656fc9d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/OpenQA/WebAPI/Controller/API/V1/Job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ sub list ($self) {
$validation->optional('limit')->num;
$validation->optional('offset')->num;
$validation->optional('groupid')->num;
$validation->optional('not_groupid')->num;

my $limits = OpenQA::App->singleton->config->{misc_limits};
my $limit = min($limits->{generic_max_limit}, $validation->param('limit') // $limits->{generic_default_limit});
Expand Down Expand Up @@ -124,6 +125,11 @@ sub list ($self) {
my $latest = $validation->param('latest');
my $schema = $self->schema;
my $rs = $schema->resultset('Jobs')->complex_query(%args);

if (defined(my $not_groupid = $self->param('not_groupid'))) {
$rs = $rs->search({group_id => {-not_in => [$not_groupid]}});
}

my @jobarray = defined $latest ? $rs->latest_jobs : $rs->all;

# Pagination
Expand Down
18 changes: 14 additions & 4 deletions lib/OpenQA/WebAPI/Controller/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -727,14 +727,24 @@ sub _prepare_job_results ($self, $all_jobs, $limit) {
}

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

my $v = $self->validation;
$v->optional('groupid')->num(0, undef);
return $v->is_valid('groupid') ? $self->every_param('groupid') : 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) {
my $schema = $self->schema;
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 656fc9d

Please sign in to comment.