diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/triggers.rb | 87 |
1 files changed, 40 insertions, 47 deletions
diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb index d1d07394e92..2312ff000fb 100644 --- a/lib/api/triggers.rb +++ b/lib/api/triggers.rb @@ -2,18 +2,19 @@ module API # Triggers API class Triggers < Grape::API resource :projects do - # Trigger a GitLab 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 - # variables (optional) - The list of variables to be injected into build - # Example Request: - # POST /projects/:id/trigger/builds + desc 'Trigger a GitLab 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: 'The list of variables to be injected into build' do + requires :key, type: String + requires :value, type: String + end + end post ":id/trigger/builds" do - required_attributes! [:ref, :token] - project = Project.find_with_namespace(params[:id]) || Project.find_by(id: params[:id]) trigger = Ci::Trigger.find_by_token(params[:token].to_s) not_found! unless project && trigger @@ -22,14 +23,6 @@ module API # 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 end @@ -44,14 +37,14 @@ module API end end - # Get triggers list - # - # Parameters: - # id (required) - The ID of a project - # page (optional) - The page number for pagination - # per_page (optional) - The value of items per page to show - # Example Request: - # GET /projects/:id/triggers + desc 'Get triggers list' do + success Entities::Trigger + end + params do + requires :id, type: Integer, desc: 'The ID of a project' + optional :page, type: Integer, desc: 'The page number for pagination' + optional :per_page, type: Integer, desc: 'The value of items per page to show' + end get ':id/triggers' do authenticate! authorize! :admin_build, user_project @@ -62,13 +55,13 @@ module API present triggers, with: Entities::Trigger end - # Get specific trigger of a project - # - # Parameters: - # id (required) - The ID of a project - # token (required) - The `token` of a trigger - # Example Request: - # GET /projects/:id/triggers/:token + desc 'Get specific trigger of a project' do + success Entities::Trigger + end + params do + requires :id, type: Integer, desc: 'The ID of a project' + requires :token, type: String, desc: 'The token of a trigger' + end get ':id/triggers/:token' do authenticate! authorize! :admin_build, user_project @@ -79,12 +72,12 @@ module API present trigger, with: Entities::Trigger end - # Create trigger - # - # Parameters: - # id (required) - The ID of a project - # Example Request: - # POST /projects/:id/triggers + desc 'Create trigger' do + success Entities::Trigger + end + params do + requires :id, type: Integer, desc: 'The ID of a project' + end post ':id/triggers' do authenticate! authorize! :admin_build, user_project @@ -94,13 +87,13 @@ module API present trigger, with: Entities::Trigger end - # Delete trigger - # - # Parameters: - # id (required) - The ID of a project - # token (required) - The `token` of a trigger - # Example Request: - # DELETE /projects/:id/triggers/:token + desc 'Delete trigger' do + success Entities::Trigger + end + params do + requires :id, type: Integer, desc: 'The ID of a project' + requires :token, type: String, desc: 'The token of a trigger' + end delete ':id/triggers/:token' do authenticate! authorize! :admin_build, user_project |