Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/ci/pipelines.rb')
-rw-r--r--lib/api/ci/pipelines.rb93
1 files changed, 92 insertions, 1 deletions
diff --git a/lib/api/ci/pipelines.rb b/lib/api/ci/pipelines.rb
index a010e0dd761..045f81074a7 100644
--- a/lib/api/ci/pipelines.rb
+++ b/lib/api/ci/pipelines.rb
@@ -15,6 +15,24 @@ module API
detail 'This feature was introduced in GitLab 8.11.'
success Entities::Ci::PipelineBasic
end
+
+ helpers do
+ params :optional_scope do
+ optional :scope, types: [String, Array[String]], desc: 'The scope of builds to show',
+ values: ::CommitStatus::AVAILABLE_STATUSES,
+ coerce_with: ->(scope) {
+ case scope
+ when String
+ [scope]
+ when ::Array
+ scope
+ else
+ ['unknown']
+ end
+ }
+ end
+ end
+
params do
use :pagination
optional :scope, type: String, values: %w[running pending finished branches tags],
@@ -96,6 +114,64 @@ module API
present pipeline, with: Entities::Ci::Pipeline
end
+ desc 'Get pipeline jobs' do
+ success Entities::Ci::Job
+ end
+ params do
+ requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
+ use :optional_scope
+ use :pagination
+ end
+
+ get ':id/pipelines/:pipeline_id/jobs' do
+ authorize!(:read_pipeline, user_project)
+
+ pipeline = user_project.all_pipelines.find(params[:pipeline_id])
+
+ if Feature.enabled?(:ci_jobs_finder_refactor)
+ builds = ::Ci::JobsFinder
+ .new(current_user: current_user, pipeline: pipeline, params: params)
+ .execute
+ else
+ authorize!(:read_build, pipeline)
+ builds = pipeline.builds
+ builds = filter_builds(builds, params[:scope])
+ end
+
+ builds = builds.with_preloads
+
+ present paginate(builds), with: Entities::Ci::Job
+ end
+
+ desc 'Get pipeline bridge jobs' do
+ success Entities::Ci::Bridge
+ end
+ params do
+ requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
+ use :optional_scope
+ use :pagination
+ end
+
+ get ':id/pipelines/:pipeline_id/bridges' do
+ authorize!(:read_build, user_project)
+
+ pipeline = user_project.all_pipelines.find(params[:pipeline_id])
+
+ if Feature.enabled?(:ci_jobs_finder_refactor)
+ bridges = ::Ci::JobsFinder
+ .new(current_user: current_user, pipeline: pipeline, params: params, type: ::Ci::Bridge)
+ .execute
+ else
+ authorize!(:read_pipeline, pipeline)
+ bridges = pipeline.bridges
+ bridges = filter_builds(bridges, params[:scope])
+ end
+
+ bridges = bridges.with_preloads
+
+ present paginate(bridges), with: Entities::Ci::Bridge
+ end
+
desc 'Gets the variables for a given pipeline' do
detail 'This feature was introduced in GitLab 11.11'
success Entities::Ci::Variable
@@ -170,6 +246,21 @@ module API
end
helpers do
+ # NOTE: This method should be removed once the ci_jobs_finder_refactor FF is
+ # removed. https://gitlab.com/gitlab-org/gitlab/-/issues/245183
+ # rubocop: disable CodeReuse/ActiveRecord
+ def filter_builds(builds, scope)
+ return builds if scope.nil? || scope.empty?
+
+ available_statuses = ::CommitStatus::AVAILABLE_STATUSES
+
+ unknown = scope - available_statuses
+ render_api_error!('Scope contains invalid value(s)', 400) unless unknown.empty?
+
+ builds.where(status: scope)
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+
def pipeline
strong_memoize(:pipeline) do
user_project.all_pipelines.find(params[:pipeline_id])
@@ -178,7 +269,7 @@ module API
def latest_pipeline
strong_memoize(:latest_pipeline) do
- user_project.latest_pipeline_for_ref(params[:ref])
+ user_project.latest_pipeline(params[:ref])
end
end
end