2017-07-26 05:31:09 -04:00
|
|
|
module Ci
|
|
|
|
class PipelineTriggerService < BaseService
|
2017-11-13 10:27:30 -05:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2017-07-26 05:31:09 -04:00
|
|
|
def execute
|
|
|
|
if trigger_from_token
|
|
|
|
create_pipeline_from_trigger(trigger_from_token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_pipeline_from_trigger(trigger)
|
|
|
|
# this check is to not leak the presence of the project if user cannot read it
|
|
|
|
return unless trigger.project == project
|
|
|
|
|
|
|
|
pipeline = Ci::CreatePipelineService.new(project, trigger.owner, ref: params[:ref])
|
|
|
|
.execute(:trigger, ignore_skip_ci: true) do |pipeline|
|
2018-03-21 05:59:11 -04:00
|
|
|
pipeline.trigger_requests.build(trigger: trigger)
|
|
|
|
pipeline.variables.build(variables)
|
2017-07-26 05:31:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if pipeline.persisted?
|
|
|
|
success(pipeline: pipeline)
|
|
|
|
else
|
|
|
|
error(pipeline.errors.messages, 400)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def trigger_from_token
|
2017-11-13 10:27:30 -05:00
|
|
|
strong_memoize(:trigger) do
|
|
|
|
Ci::Trigger.find_by_token(params[:token].to_s)
|
|
|
|
end
|
2017-07-26 05:31:09 -04:00
|
|
|
end
|
|
|
|
|
2018-03-21 05:59:11 -04:00
|
|
|
def variables
|
|
|
|
params[:variables].to_h.map do |key, value|
|
2017-07-26 05:31:09 -04:00
|
|
|
{ key: key, value: value }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|