diff --git a/src/lib/Hydra/Controller/API.pm b/src/lib/Hydra/Controller/API.pm index 3ddee97a..f4936982 100644 --- a/src/lib/Hydra/Controller/API.pm +++ b/src/lib/Hydra/Controller/API.pm @@ -254,8 +254,10 @@ sub push : Chained('api') PathPart('push') Args(0) { foreach my $r (@repos) { triggerJobset($self, $c, $_, $force) foreach $c->model('DB::Jobsets')->search( { 'project.enabled' => 1, 'me.enabled' => 1 }, - { join => 'project' - , where => \ [ 'exists (select 1 from JobsetInputAlts where project = me.project and jobset = me.name and value = ?)', [ 'value', $r ] ] + { + join => 'project', + where => \ [ 'exists (select 1 from JobsetInputAlts where project = me.project and jobset = me.name and value = ?)', [ 'value', $r ] ], + order_by => 'me.id DESC' }); } diff --git a/t/Hydra/Controller/API/checks.t b/t/Hydra/Controller/API/checks.t index c133f098..4aac3fbf 100644 --- a/t/Hydra/Controller/API/checks.t +++ b/t/Hydra/Controller/API/checks.t @@ -100,4 +100,45 @@ subtest "/api/nrbuilds" => sub { }; }; +subtest "/api/push" => sub { + subtest "with a specific jobset" => sub { + my $build = $finishedBuilds->{"one_job"}; + my $jobset = $build->jobset; + my $projectName = $jobset->project->name; + my $jobsetName = $jobset->name; + is($jobset->forceeval, undef, "The existing jobset is not set to be forced to eval"); + + my $response = request(GET "/api/push?jobsets=$projectName:$jobsetName&force=1"); + ok($response->is_success, "The API enpdoint for triggering jobsets returns 200."); + + my $data = is_json($response); + is($data, { jobsetsTriggered => [ "$projectName:$jobsetName" ] }); + + my $updatedJobset = $ctx->db->resultset('Jobsets')->find({ id => $jobset->id }); + is($updatedJobset->forceeval, 1, "The jobset is now forced to eval"); + }; + + subtest "with a specific source" => sub { + my $repo = $ctx->jobsdir; + my $jobsetA = $queuedBuilds->{"one_job"}->jobset; + my $jobsetB = $finishedBuilds->{"one_job"}->jobset; + + is($jobsetA->forceeval, undef, "The existing jobset is not set to be forced to eval"); + + print STDERR $repo; + + my $response = request(GET "/api/push?repos=$repo&force=1"); + ok($response->is_success, "The API enpdoint for triggering jobsets returns 200."); + + my $data = is_json($response); + is($data, { jobsetsTriggered => [ + "${\$jobsetA->project->name}:${\$jobsetA->name}", + "${\$jobsetB->project->name}:${\$jobsetB->name}" + ] }); + + my $updatedJobset = $ctx->db->resultset('Jobsets')->find({ id => $jobsetA->id }); + is($updatedJobset->forceeval, 1, "The jobset is now forced to eval"); + }; +}; + done_testing;