diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/triggers.rb | 9 | ||||
-rw-r--r-- | lib/api/v3/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/v3/triggers.rb | 12 | ||||
-rw-r--r-- | lib/ci/api/entities.rb | 5 | ||||
-rw-r--r-- | lib/ci/api/triggers.rb | 22 | ||||
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 30 |
6 files changed, 37 insertions, 45 deletions
diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb index 1d3767c78ff..311ba248d1a 100644 --- a/lib/api/triggers.rb +++ b/lib/api/triggers.rb @@ -32,9 +32,10 @@ module API 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 + pipeline = Ci::CreatePipelineService.new(project, nil, ref: params[:ref].to_s). + execute(ignore_skip_ci: true, trigger: trigger, trigger_variables: variables) + if pipeline + present pipeline, with: Entities::Pipeline else errors = 'No pipeline created' render_api_error!(errors, 400) @@ -51,7 +52,7 @@ module API authenticate! authorize! :admin_build, user_project - triggers = user_project.triggers.includes(:trigger_requests) + triggers = user_project.triggers present paginate(triggers), with: Entities::Trigger end diff --git a/lib/api/v3/entities.rb b/lib/api/v3/entities.rb index 9239c7fd168..3cc0dc968a8 100644 --- a/lib/api/v3/entities.rb +++ b/lib/api/v3/entities.rb @@ -11,10 +11,6 @@ module API Gitlab::UrlBuilder.build(snippet) end end - - class TriggerRequest < Grape::Entity - expose :id, :variables - end end end end diff --git a/lib/api/v3/triggers.rb b/lib/api/v3/triggers.rb index 8af182fdd2c..a7d669dfd4f 100644 --- a/lib/api/v3/triggers.rb +++ b/lib/api/v3/triggers.rb @@ -5,9 +5,7 @@ module API requires :id, type: String, desc: 'The ID of a project' end resource :projects do - desc 'Trigger a GitLab project build' do - success V3::Entities::TriggerRequest - end + desc 'Trigger a GitLab project build' params do requires :ref, type: String, desc: 'The commit sha or name of a branch or tag' requires :token, type: String, desc: 'The unique token of trigger' @@ -31,9 +29,11 @@ module API 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, with: Entities::TriggerRequest + pipeline = Ci::CreatePipelineService.new(project, nil, ref: params[:ref].to_s). + execute(ignore_skip_ci: true, trigger: trigger, trigger_variables: variables) + if pipeline + data = { id: pipeline.trigger_id, variables: pipeline.trigger_variables } + present data else errors = 'No builds created' render_api_error!(errors, 400) diff --git a/lib/ci/api/entities.rb b/lib/ci/api/entities.rb index 792ff628b09..bf94ed43ac6 100644 --- a/lib/ci/api/entities.rb +++ b/lib/ci/api/entities.rb @@ -69,11 +69,6 @@ module Ci class WebHook < Grape::Entity expose :id, :project_id, :url end - - class TriggerRequest < Grape::Entity - expose :id, :variables - expose :pipeline, using: Commit, as: :commit - end end end end diff --git a/lib/ci/api/triggers.rb b/lib/ci/api/triggers.rb index 63b42113513..1a82bc8fc8a 100644 --- a/lib/ci/api/triggers.rb +++ b/lib/ci/api/triggers.rb @@ -3,14 +3,12 @@ module Ci # 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' + params do + requires :ref, type: String, desc: 'The commit sha or name of a branch or tag' + requires :token, type: String, desc: 'The unique token of trigger' + optional :variables, type: Hash, desc: 'The list of variables to be injected into build' + end post ":id/refs/:ref/trigger" do required_attributes! [:token] @@ -35,9 +33,11 @@ module Ci 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, with: Entities::TriggerRequest + pipeline = Ci::CreatePipelineService.new(project, nil, ref: params[:ref].to_s). + execute(ignore_skip_ci: true, trigger: trigger, trigger_variables: variables) + if pipeline + data = { id: pipeline.trigger_id, variables: pipeline.trigger_variables } + present data else errors = 'No builds created' render_api_error!(errors, 400) diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index 649ee4d018b..734b7743101 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -20,26 +20,26 @@ module Ci raise ValidationError, e.message end - def jobs_for_ref(ref, tag = false, trigger_request = nil) + def jobs_for_ref(ref, tag = false, trigger = nil) @jobs.select do |_, job| - process?(job[:only], job[:except], ref, tag, trigger_request) + process?(job[:only], job[:except], ref, tag, trigger) end end - def jobs_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil) - jobs_for_ref(ref, tag, trigger_request).select do |_, job| + def jobs_for_stage_and_ref(stage, ref, tag = false, trigger = nil) + jobs_for_ref(ref, tag, trigger).select do |_, job| job[:stage] == stage end end - def builds_for_ref(ref, tag = false, trigger_request = nil) - jobs_for_ref(ref, tag, trigger_request).map do |name, _| + def builds_for_ref(ref, tag = false, trigger = nil) + jobs_for_ref(ref, tag, trigger).map do |name, _| build_attributes(name) end end - def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil) - jobs_for_stage_and_ref(stage, ref, tag, trigger_request).map do |name, _| + def builds_for_stage_and_ref(stage, ref, tag = false, trigger = nil) + jobs_for_stage_and_ref(stage, ref, tag, trigger).map do |name, _| build_attributes(name) end end @@ -181,30 +181,30 @@ module Ci end end - def process?(only_params, except_params, ref, tag, trigger_request) + def process?(only_params, except_params, ref, tag, trigger) if only_params.present? - return false unless matching?(only_params, ref, tag, trigger_request) + return false unless matching?(only_params, ref, tag, trigger) end if except_params.present? - return false if matching?(except_params, ref, tag, trigger_request) + return false if matching?(except_params, ref, tag, trigger) end true end - def matching?(patterns, ref, tag, trigger_request) + def matching?(patterns, ref, tag, trigger) patterns.any? do |pattern| - match_ref?(pattern, ref, tag, trigger_request) + match_ref?(pattern, ref, tag, trigger) end end - def match_ref?(pattern, ref, tag, trigger_request) + def match_ref?(pattern, ref, tag, trigger) pattern, path = pattern.split('@', 2) return false if path && path != self.path return true if tag && pattern == 'tags' return true if !tag && pattern == 'branches' - return true if trigger_request.present? && pattern == 'triggers' + return true if trigger.present? && pattern == 'triggers' if pattern.first == "/" && pattern.last == "/" Regexp.new(pattern[1...-1]) =~ ref |