Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow searching for jobs by comment text #5425

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/javascripts/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function renderTestLists() {
this[paramName] = paramValues[0];
}
};
jQuery.each(['limit', 'groupid', 'match', 'group_glob', 'not_group_glob'], (index, paramName) => {
jQuery.each(['limit', 'groupid', 'match', 'group_glob', 'not_group_glob', 'comment'], (index, paramName) => {
ajaxQueryParams.addFirstParam(paramName);
});
delete ajaxQueryParams.addFirstParam;
Expand Down
4 changes: 4 additions & 0 deletions lib/OpenQA/Schema/ResultSet/Jobs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ sub _prepare_complex_query_search_args ($self, $args) {
}
}

if (defined(my $c = $args->{comment_text})) {
push @conds, \["(select id from comments where job_id = me.id and text like ? limit 1) is not null", "%$c%"];
}

push(@conds, @{$args->{additional_conds}}) if $args->{additional_conds};
my %attrs;
$attrs{columns} = $args->{columns} if $args->{columns};
Expand Down
3 changes: 3 additions & 0 deletions lib/OpenQA/WebAPI/Controller/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ sub list_ajax ($self) {
state => [OpenQA::Jobs::Constants::FINAL_STATES],
scope => $scope,
match => $self->get_match_param,
comment_text => $self->param('comment'),
groupids => $self->_prepare_groupids,
limit => min(
$limits->{all_tests_max_finished_jobs},
Expand Down Expand Up @@ -214,6 +215,7 @@ sub list_running_ajax {
my $running = $self->schema->resultset('Jobs')->complex_query(
state => [OpenQA::Jobs::Constants::EXECUTION_STATES],
match => $self->get_match_param,
comment_text => $self->param('comment'),
groupid => $self->param('groupid'),
order_by => [{-desc => 'me.t_started'}, {-desc => 'me.id'}],
columns => [
Expand Down Expand Up @@ -261,6 +263,7 @@ sub list_scheduled_ajax {
my $scheduled = $self->schema->resultset('Jobs')->complex_query(
state => [OpenQA::Jobs::Constants::PRE_EXECUTION_STATES],
match => $self->get_match_param,
comment_text => $self->param('comment'),
groupid => $self->param('groupid'),
order_by => [{-desc => 'me.t_created'}, {-desc => 'me.id'}],
columns => [
Expand Down
4 changes: 4 additions & 0 deletions lib/OpenQA/WebAPI/Plugin/Helpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ sub _compose_job_overview_search_args ($c) {

my $v = $c->validation;
$v->optional($_, 'not_empty') for JOBS_OVERVIEW_SEARCH_CRITERIA;
$v->optional('comment');
$v->optional('groupid')->num(0, undef);
$v->optional('modules', 'comma_separated');
$v->optional('limit', 'not_empty')->num(0, undef);
Expand Down Expand Up @@ -488,6 +489,9 @@ sub _compose_job_overview_search_args ($c) {
# allow filtering by group ID or group name
$search_args{groupids} = [map { $_->id } @groups] if @groups;

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

return (\%search_args, \@groups);
}

Expand Down
8 changes: 8 additions & 0 deletions t/10-tests_overview.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sub get_summary { OpenQA::Test::Case::trim_whitespace($t->tx->res->dom->at('#sum

my $jobs = $schema->resultset('Jobs');
$jobs->find(99928)->update({blocked_by_id => 99927});
$jobs->find($_)->comments->create({text => 'foobar', user_id => 99901}) for 99946, 99963;
$t->get_ok('/tests/overview' => form => {distri => 'opensuse', version => '13.1', build => '0091'})->status_is(200);

my $summary = get_summary;
Expand Down Expand Up @@ -346,6 +347,13 @@ like(get_summary, qr/current time Failed: 1$/i);
$t->element_exists('#res_DVD_x86_64_doc .result_failed', 'job with failed module logpackages still shown');
$t->element_exists_not('#res_DVD_x86_64_kde .result_passed', 'passed job hidden');

subtest 'comment parameter' => sub {
$t->get_ok('/tests/overview?groupid=1001&distri=opensuse&version=13.1&build=0091&comment=oob');
$t->status_is(200);
my $ids = $t->tx->res->dom->find('.overview span[id^="res-"]')->map(attr => 'id')->sort->to_array;
is_deeply $ids, [qw(res-99946 res-99963)], 'expected set of jobs present';
};

# Check if another random module has failed
$latest_job->update({DISTRI => 'opensuse'});
my $failing_module = $schema->resultset('JobModules')->create(
Expand Down
21 changes: 15 additions & 6 deletions t/ui/01-list.t
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,22 @@ subtest 'filter-finished' => sub {
cmp_ok scalar $driver->find_elements('#results tbody tr', 'css'), '>', scalar @jobs, 'all jobs shown again';
};

$driver->get('/tests?match=staging_e');
wait_for_ajax();
subtest 'match parameter' => sub {
$driver->get('/tests?match=staging_e');
wait_for_ajax msg => '"All tests" with match parameter';
@jobs = map { $_->get_attribute('id') } @{$driver->find_elements('tbody tr', 'css')};
ok !$jobs[0], 'no running job matching';
ok !$jobs[1], 'no scheduled job matching';
is $jobs[2], 'job_99926', 'exactly one finished job matching';
};

@jobs = map { $_->get_attribute('id') } @{$driver->find_elements('tbody tr', 'css')};
ok !$jobs[0], 'no running job matching';
ok !$jobs[1], 'no scheduled job matching';
is $jobs[2], 'job_99926', 'exactly one finished job matching';
subtest 'comment parameter' => sub {
$driver->get('/tests?comment=test1');
wait_for_ajax msg => '"All tests" with comment parameter';
is_deeply [map { $_->get_attribute('id') } @{$driver->find_elements('tbody tr', 'css')}],
[qw(job_99963 job_99928 job_99946)],
'exactly one running, scheduled and finished job match';
};

$driver->get('/tests');
wait_for_ajax();
Expand Down
Loading