diff options
author | Connor Shea <connor.james.shea@gmail.com> | 2016-09-14 01:00:59 +0300 |
---|---|---|
committer | Connor Shea <connor.james.shea@gmail.com> | 2016-09-14 01:00:59 +0300 |
commit | dda6719b3b6c45a64b38d62c43561dce7a31bdd2 (patch) | |
tree | a80813a44c3c294d1ba8d554fa5c8749bd838ee8 | |
parent | 960d1752631cb97e5ca6932ab9247ff0570cbef3 (diff) |
Convert triggers.rb, this has a lot of failing tests, not entirely sure why.grapify-all-the-things
-rw-r--r-- | lib/api/triggers.rb | 87 | ||||
-rw-r--r-- | spec/requests/api/triggers_spec.rb | 4 |
2 files changed, 42 insertions, 49 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 diff --git a/spec/requests/api/triggers_spec.rb b/spec/requests/api/triggers_spec.rb index 82bba1ce8a4..c3d223e4514 100644 --- a/spec/requests/api/triggers_spec.rb +++ b/spec/requests/api/triggers_spec.rb @@ -68,13 +68,13 @@ describe API::API do it 'validates variables to be a hash' do post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: 'value', ref: 'master') expect(response).to have_http_status(400) - expect(json_response['message']).to eq('variables needs to be a hash') + expect(json_response['error']).to include('variables is invalid') end it 'validates variables needs to be a map of key-valued strings' do post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: { key: %w(1 2) }, ref: 'master') expect(response).to have_http_status(400) - expect(json_response['message']).to eq('variables needs to be a map of key-valued strings') + expect(json_response['error']).to include('variables[value] is missing') end it 'creates trigger request with variables' do |