Commit 1f80392d authored by Laura Montemayor's avatar Laura Montemayor Committed by Igor Drozdov

Adds bridge support to play api

* Adds a find_job helper method to find both bridges and builds
* Updates specs for jobs_finder to include bridges
* Adds a find_job spec to helper specs
parent 3b140ad4
---
title: Add manual bridge support to api
merge_request: 50634
author:
type: changed
...@@ -220,6 +220,10 @@ module API ...@@ -220,6 +220,10 @@ module API
user_project.builds.find(id.to_i) user_project.builds.find(id.to_i)
end end
def find_job!(id)
user_project.processables.find(id.to_i)
end
def authenticate! def authenticate!
unauthorized! unless current_user unauthorized! unless current_user
end end
......
...@@ -138,25 +138,32 @@ module API ...@@ -138,25 +138,32 @@ module API
present build, with: Entities::Ci::Job present build, with: Entities::Ci::Job
end end
desc 'Trigger a actionable job (manual, delayed, etc)' do desc 'Trigger an actionable job (manual, delayed, etc)' do
success Entities::Ci::Job success Entities::Ci::JobBasic
detail 'This feature was added in GitLab 8.11' detail 'This feature was added in GitLab 8.11'
end end
params do params do
requires :job_id, type: Integer, desc: 'The ID of a Job' requires :job_id, type: Integer, desc: 'The ID of a Job'
end end
post ":id/jobs/:job_id/play" do post ":id/jobs/:job_id/play" do
authorize_read_builds! authorize_read_builds!
build = find_build!(params[:job_id]) job = find_job!(params[:job_id])
authorize!(:update_build, build) authorize!(:play_job, job)
bad_request!("Unplayable Job") unless build.playable?
bad_request!("Unplayable Job") unless job.playable?
build.play(current_user) job.play(current_user)
status 200 status 200
present build, with: Entities::Ci::Job
if job.is_a?(::Ci::Build)
present job, with: Entities::Ci::Job
else
present job, with: Entities::Ci::Bridge
end
end end
end end
......
...@@ -1007,10 +1007,26 @@ RSpec.describe API::Jobs do ...@@ -1007,10 +1007,26 @@ RSpec.describe API::Jobs do
post api("/projects/#{project.id}/jobs/#{job.id}/play", api_user) post api("/projects/#{project.id}/jobs/#{job.id}/play", api_user)
end end
context 'on an playable job' do context 'on a playable job' do
let(:job) { create(:ci_build, :manual, project: project, pipeline: pipeline) } let_it_be(:job) { create(:ci_bridge, :playable, pipeline: pipeline, downstream: project) }
before do
project.add_developer(user)
end
context 'when user is authorized to trigger a manual action' do context 'when user is authorized to trigger a manual action' do
context 'that is a bridge' do
it 'plays the job' do
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['user']['id']).to eq(user.id)
expect(json_response['id']).to eq(job.id)
expect(job.reload).to be_pending
end
end
context 'that is a build' do
let_it_be(:job) { create(:ci_build, :manual, project: project, pipeline: pipeline) }
it 'plays the job' do it 'plays the job' do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['user']['id']).to eq(user.id) expect(json_response['user']['id']).to eq(user.id)
...@@ -1018,6 +1034,7 @@ RSpec.describe API::Jobs do ...@@ -1018,6 +1034,7 @@ RSpec.describe API::Jobs do
expect(job.reload).to be_pending expect(job.reload).to be_pending
end end
end end
end
context 'when user is not authorized to trigger a manual action' do context 'when user is not authorized to trigger a manual action' do
context 'when user does not have access to the project' do context 'when user does not have access to the project' do
......
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