diff options
author | Rémy Coutable <remy@rymai.me> | 2017-02-22 13:11:04 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-02-22 13:11:04 +0000 |
commit | 9aaf38d6cfc67652f0239b25eae36ab6517ea02f (patch) | |
tree | d7293bfdc4a007376a18a36a75b32bb2b1beb5df /lib | |
parent | 7813ceddf7bb175510c9be03ec182d2514d583a2 (diff) | |
parent | b8c88a839da9722f17bc7a851af2fae15e1ab1c5 (diff) | |
download | gitlab-ce-9aaf38d6cfc67652f0239b25eae36ab6517ea02f.tar.gz |
Merge branch 'grapify-ci-triggers-api' into 'master'
Grapfiy the CI::Triggers API
See merge request !9439
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ci/api/triggers.rb | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/lib/ci/api/triggers.rb b/lib/ci/api/triggers.rb index 63b42113513..6e622601680 100644 --- a/lib/ci/api/triggers.rb +++ b/lib/ci/api/triggers.rb @@ -1,41 +1,30 @@ module Ci module API - # Build Trigger API class Triggers < Grape::API resource :projects do - # Trigger a GitLab CI project build - # - # Parameters: - # id (required) - The ID of a CI project - # ref (required) - The name of project's branch or tag - # token (required) - The uniq token of trigger - # Example Request: - # POST /projects/:id/ref/:ref/trigger + desc 'Trigger a GitLab CI project build' do + success Entities::TriggerRequest + end + params do + requires :id, type: Integer, desc: 'The ID of a CI project' + requires :ref, type: String, desc: "The name of project's branch or tag" + requires :token, type: String, desc: 'The unique token of the trigger' + optional :variables, type: Hash, desc: 'Optional build variables' + end post ":id/refs/:ref/trigger" do - required_attributes! [:token] - - project = Project.find_by(ci_id: params[:id].to_i) - trigger = Ci::Trigger.find_by_token(params[:token].to_s) + project = Project.find_by(ci_id: params[:id]) + trigger = Ci::Trigger.find_by_token(params[:token]) not_found! unless project && trigger unauthorized! unless trigger.project == project - # validate variables - variables = params[:variables] - if variables - unless variables.is_a?(Hash) - render_api_error!('variables needs to be a hash', 400) - end - - unless 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 - - # convert variables from Mash to Hash - variables = variables.to_h + # Validate variables + variables = params[:variables].to_h + unless 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) + trigger_request = Ci::CreateTriggerRequestService.new.execute(project, trigger, params[:ref], variables) if trigger_request present trigger_request, with: Entities::TriggerRequest else |