Commit e7082e89 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'lm-manual-bridge-support' into 'master'

Adds manual bridge support to public API

See merge request gitlab-org/gitlab!50634
parents a01d8a60 1f80392d
---
title: Add manual bridge support to api
merge_request: 50634
author:
type: changed
......@@ -220,6 +220,10 @@ module API
user_project.builds.find(id.to_i)
end
def find_job!(id)
user_project.processables.find(id.to_i)
end
def authenticate!
unauthorized! unless current_user
end
......
......@@ -138,25 +138,32 @@ module API
present build, with: Entities::Ci::Job
end
desc 'Trigger a actionable job (manual, delayed, etc)' do
success Entities::Ci::Job
desc 'Trigger an actionable job (manual, delayed, etc)' do
success Entities::Ci::JobBasic
detail 'This feature was added in GitLab 8.11'
end
params do
requires :job_id, type: Integer, desc: 'The ID of a Job'
end
post ":id/jobs/:job_id/play" do
authorize_read_builds!
build = find_build!(params[:job_id])
job = find_job!(params[:job_id])
authorize!(:update_build, build)
bad_request!("Unplayable Job") unless build.playable?
authorize!(:play_job, job)
build.play(current_user)
bad_request!("Unplayable Job") unless job.playable?
job.play(current_user)
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
......
......@@ -1007,15 +1007,32 @@ RSpec.describe API::Jobs do
post api("/projects/#{project.id}/jobs/#{job.id}/play", api_user)
end
context 'on an playable job' do
let(:job) { create(:ci_build, :manual, project: project, pipeline: pipeline) }
context 'on a playable job' do
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
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
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
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
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