Allow filtering by 'status'

This commit is contained in:
Tomasz Maczukin 2017-11-21 12:37:07 +01:00
parent 8d3e80692c
commit b7ed102ea6
No known key found for this signature in database
GPG Key ID: 7E9EB2E4B0F625CD
2 changed files with 54 additions and 5 deletions

View File

@ -90,13 +90,20 @@ module API
end
params do
requires :id, type: Integer, desc: 'The ID of the runner'
optional :status, type: String, desc: 'Status of job'
use :pagination
end
get ':id/jobs' do
runner = get_runner(params[:id])
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

View File

@ -370,8 +370,8 @@ describe API::Runners do
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response.length).to eq(1)
expect(json_response[0]).to include('id' => job_2.id)
expect(json_response).to be_an(Array)
expect(json_response.length).to eq(2)
end
end
@ -382,8 +382,29 @@ describe API::Runners do
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(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[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
@ -414,8 +435,29 @@ describe API::Runners do
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(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[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