summaryrefslogtreecommitdiff
path: root/lib/api/triggers.rb
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-08-02 16:37:40 +0100
committerPhil Hughes <me@iamphill.com>2017-08-02 16:37:40 +0100
commite4c20cd3fe330faa415493ee2fe30dc16fbaca80 (patch)
tree0be61b6cc59cf35d81b9271c7603e0d8b203a31c /lib/api/triggers.rb
parent25d6a6c4b528159c288995de4909e6a8da431d0b (diff)
parent88958e5a9cd364ae36f3d2837982cedb9239c3bc (diff)
downloadgitlab-ce-e4c20cd3fe330faa415493ee2fe30dc16fbaca80.tar.gz
Merge branch 'master' into sidebar-fly-out-sub-navsidebar-fly-out-sub-nav
Diffstat (limited to 'lib/api/triggers.rb')
-rw-r--r--lib/api/triggers.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb
index cb0619105e1..edfdb63d183 100644
--- a/lib/api/triggers.rb
+++ b/lib/api/triggers.rb
@@ -15,24 +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
- trigger_request = Ci::CreateTriggerRequestService.new.execute(project, trigger, params[:ref].to_s, variables)
- if trigger_request
- present trigger_request.pipeline, with: Entities::Pipeline
+ project = find_project(params[:id])
+ not_found! unless project
+
+ result = Ci::PipelineTriggerService.new(project, nil, params).execute
+ not_found! unless result
+
+ if result[:http_status]
+ render_api_error!(result[:message], result[:http_status])
else
- errors = 'No pipeline created'
- render_api_error!(errors, 400)
+ present result[:pipeline], with: Entities::Pipeline
end
end