Commit b7ed102e authored by Tomasz Maczukin's avatar Tomasz Maczukin

Allow filtering by 'status'

parent 8d3e8069
...@@ -90,13 +90,20 @@ module API ...@@ -90,13 +90,20 @@ module API
end end
params do params do
requires :id, type: Integer, desc: 'The ID of the runner' requires :id, type: Integer, desc: 'The ID of the runner'
optional :status, type: String, desc: 'Status of job'
use :pagination use :pagination
end end
get ':id/jobs' do get ':id/jobs' do
runner = get_runner(params[:id]) runner = get_runner(params[:id])
authenticate_list_runners_jobs!(runner) authenticate_list_runners_jobs!(runner)
present paginate(runner.builds.running), with: Entities::JobWithProject jobs = runner.builds
if params[:status]
not_found!('Status') unless Ci::Build::AVAILABLE_STATUSES.include?(params[:status])
jobs = jobs.where(status: params[:status].to_sym)
end
present paginate(jobs), with: Entities::JobWithProject
end end
end end
......
...@@ -370,8 +370,8 @@ describe API::Runners do ...@@ -370,8 +370,8 @@ describe API::Runners do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response.length).to eq(1) expect(json_response).to be_an(Array)
expect(json_response[0]).to include('id' => job_2.id) expect(json_response.length).to eq(2)
end end
end end
...@@ -382,8 +382,29 @@ describe API::Runners do ...@@ -382,8 +382,29 @@ describe API::Runners do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an(Array)
expect(json_response.length).to eq(2)
end
end
context 'when valid status is provided' do
it 'return filtered jobs' do
get api("/runners/#{specific_runner.id}/jobs?status=failed", admin)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an(Array)
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response[0]).to include('id' => job_4.id) expect(json_response.first).to include('id' => job_5.id)
end
end
context 'when invalid status is provided' do
it 'return 404' do
get api("/runners/#{specific_runner.id}/jobs?status=non-existing", admin)
expect(response).to have_gitlab_http_status(404)
end end
end end
end end
...@@ -414,8 +435,29 @@ describe API::Runners do ...@@ -414,8 +435,29 @@ describe API::Runners do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an(Array)
expect(json_response.length).to eq(2)
end
end
context 'when valid status is provided' do
it 'return filtered jobs' do
get api("/runners/#{specific_runner.id}/jobs?status=failed", user)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an(Array)
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response[0]).to include('id' => job_4.id) expect(json_response.first).to include('id' => job_5.id)
end
end
context 'when invalid status is provided' do
it 'return 404' do
get api("/runners/#{specific_runner.id}/jobs?status=non-existing", user)
expect(response).to have_gitlab_http_status(404)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment