diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-09-06 13:18:53 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-09-06 13:18:53 +0100 |
commit | 0e1404d441b0db532046d50dcbaf754ff4d3a77e (patch) | |
tree | 87a5b482c31e846d5e799291aa9852a008732c2a /lib/api/v3/triggers.rb | |
parent | fa0f9d60e2be51261f4f58c25d75229ba996659d (diff) | |
parent | ba302454e1191f28453929df80e13c4dd418f8c7 (diff) | |
download | gitlab-ce-collapsable-pipeline-settings.tar.gz |
Merge branch 'master' into collapsable-pipeline-settingscollapsable-pipeline-settings
* master: (260 commits)
Enable auto-retry in GitLab CI/CD pipeline
Clean up new navigation templates
Wait for gitaly to boot during tests
Update 'Visibility of pipelines'
refactored code
Fix note resolution specs
Add author and MR to changelog
Tidy up projects API specs
Resolve outdated diff discussions on push
Fix migration
change collapse to resolve and comments to discussions
add unit tests for new collapse_outdated_diff_comments toggle
Add functionality to collapse outdated diff comments regardless of discussion resolution
refactor code based on feedback
fix spec failures
Use flexbox for prometheus graph row grouping instead of bootstrap classes
Fix wrong API status codes
small refactor
Hide admin link from default search results for non-admins
Make search dropdowns consistent
...
Diffstat (limited to 'lib/api/v3/triggers.rb')
-rw-r--r-- | lib/api/v3/triggers.rb | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/api/v3/triggers.rb b/lib/api/v3/triggers.rb index e9d4c35307b..534911fde5c 100644 --- a/lib/api/v3/triggers.rb +++ b/lib/api/v3/triggers.rb @@ -16,25 +16,31 @@ module API optional :variables, type: Hash, desc: 'The list of variables to be injected into build' end post ":id/(ref/:ref/)trigger/builds", 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 result.trigger_request, with: ::API::V3::Entities::TriggerRequest + if result[:http_status] + render_api_error!(result[:message], result[:http_status]) else - render_validation_error!(pipeline) + pipeline = result[:pipeline] + + # We switched to Ci::PipelineVariable from Ci::TriggerRequest.variables. + # Ci::TriggerRequest doesn't save variables anymore. + # Here is copying Ci::PipelineVariable to Ci::TriggerRequest.variables for presenting the variables. + # The same endpoint in v4 API pressents Pipeline instead of TriggerRequest, so it doesn't need such a process. + trigger_request = pipeline.trigger_requests.last + trigger_request.variables = params[:variables] + + present trigger_request, with: ::API::V3::Entities::TriggerRequest end end |