diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-07-26 18:31:09 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-07-28 18:13:29 +0900 |
commit | 56418e85ac6b667d19495665860092ce4d74f55d (patch) | |
tree | 5741323fb221a1ccd30973fd399e50a47c94393c /lib/api/triggers.rb | |
parent | 190fae5f0cef11d68c7385be0c4013931796f958 (diff) | |
download | gitlab-ce-56418e85ac6b667d19495665860092ce4d74f55d.tar.gz |
init
Diffstat (limited to 'lib/api/triggers.rb')
-rw-r--r-- | lib/api/triggers.rb | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb index 9375e7eb768..edfdb63d183 100644 --- a/lib/api/triggers.rb +++ b/lib/api/triggers.rb @@ -15,25 +15,22 @@ module API optional :variables, type: Hash, desc: 'The list of variables to be injected into build' end post ":id/(ref/:ref/)trigger/pipeline", requirements: { ref: /.+/ } do - project = find_project(params[:id]) - trigger = Ci::Trigger.find_by_token(params[:token].to_s) - not_found! unless project && trigger - unauthorized! unless trigger.project == project - # validate variables - variables = params[:variables].to_h - unless variables.all? { |key, value| key.is_a?(String) && value.is_a?(String) } + params[:variables] = params[:variables].to_h + unless params[:variables].all? { |key, value| key.is_a?(String) && value.is_a?(String) } render_api_error!('variables needs to be a map of key-valued strings', 400) end - # create request and trigger builds - result = Ci::CreateTriggerRequestService.execute(project, trigger, params[:ref].to_s, variables) - pipeline = result.pipeline + project = find_project(params[:id]) + not_found! unless project + + result = Ci::PipelineTriggerService.new(project, nil, params).execute + not_found! unless result - if pipeline.persisted? - present pipeline, with: Entities::Pipeline + if result[:http_status] + render_api_error!(result[:message], result[:http_status]) else - render_validation_error!(pipeline) + present result[:pipeline], with: Entities::Pipeline end end |