Commit df9f1676 authored by Allison Browne's avatar Allison Browne Committed by Robert Speicher

Move Entities to ci namespace

Move job variable and pipeline entities
parent 19240517
...@@ -22,7 +22,7 @@ class BlockingMergeRequestEntity < Grape::Entity ...@@ -22,7 +22,7 @@ class BlockingMergeRequestEntity < Grape::Entity
expose :head_pipeline, expose :head_pipeline,
if: -> (_, _) { can_read_head_pipeline? }, if: -> (_, _) { can_read_head_pipeline? },
using: ::API::Entities::Pipeline using: ::API::Entities::Ci::Pipeline
expose :assignees, using: ::API::Entities::UserBasic expose :assignees, using: ::API::Entities::UserBasic
expose :milestone, using: ::API::Entities::Milestone expose :milestone, using: ::API::Entities::Milestone
......
...@@ -7,7 +7,7 @@ module EE ...@@ -7,7 +7,7 @@ module EE
expose :id expose :id
expose :merge_request, using: ::API::Entities::MergeRequestSimple expose :merge_request, using: ::API::Entities::MergeRequestSimple
expose :user, using: ::API::Entities::UserBasic expose :user, using: ::API::Entities::UserBasic
expose :pipeline, using: ::API::Entities::PipelineBasic expose :pipeline, using: ::API::Entities::Ci::PipelineBasic
expose :created_at expose :created_at
expose :updated_at expose :updated_at
expose :target_branch expose :target_branch
......
...@@ -12,7 +12,7 @@ module API ...@@ -12,7 +12,7 @@ module API
namespace 'ci' do namespace 'ci' do
namespace 'variables' do namespace 'variables' do
desc 'Get instance-level variables' do desc 'Get instance-level variables' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
use :pagination use :pagination
...@@ -20,11 +20,11 @@ module API ...@@ -20,11 +20,11 @@ module API
get '/' do get '/' do
variables = ::Ci::InstanceVariable.all variables = ::Ci::InstanceVariable.all
present paginate(variables), with: Entities::Variable present paginate(variables), with: Entities::Ci::Variable
end end
desc 'Get a specific variable from a group' do desc 'Get a specific variable from a group' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :key, type: String, desc: 'The key of the variable' requires :key, type: String, desc: 'The key of the variable'
...@@ -35,11 +35,11 @@ module API ...@@ -35,11 +35,11 @@ module API
break not_found!('InstanceVariable') unless variable break not_found!('InstanceVariable') unless variable
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
end end
desc 'Create a new instance-level variable' do desc 'Create a new instance-level variable' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :key, requires :key,
...@@ -69,14 +69,14 @@ module API ...@@ -69,14 +69,14 @@ module API
variable = ::Ci::InstanceVariable.new(variable_params) variable = ::Ci::InstanceVariable.new(variable_params)
if variable.save if variable.save
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
else else
render_validation_error!(variable) render_validation_error!(variable)
end end
end end
desc 'Update an existing instance-variable' do desc 'Update an existing instance-variable' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
optional :key, optional :key,
...@@ -108,14 +108,14 @@ module API ...@@ -108,14 +108,14 @@ module API
variable_params = declared_params(include_missing: false).except(:key) variable_params = declared_params(include_missing: false).except(:key)
if variable.update(variable_params) if variable.update(variable_params)
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
else else
render_validation_error!(variable) render_validation_error!(variable)
end end
end end
desc 'Delete an existing instance-level variable' do desc 'Delete an existing instance-level variable' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :key, type: String, desc: 'The key of the variable' requires :key, type: String, desc: 'The key of the variable'
......
...@@ -12,7 +12,7 @@ module API ...@@ -12,7 +12,7 @@ module API
end end
resource :projects, requirements: ::API::API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :projects, requirements: ::API::API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get all pipeline schedules' do desc 'Get all pipeline schedules' do
success Entities::PipelineSchedule success Entities::Ci::PipelineSchedule
end end
params do params do
use :pagination use :pagination
...@@ -25,22 +25,22 @@ module API ...@@ -25,22 +25,22 @@ module API
schedules = ::Ci::PipelineSchedulesFinder.new(user_project).execute(scope: params[:scope]) schedules = ::Ci::PipelineSchedulesFinder.new(user_project).execute(scope: params[:scope])
.preload([:owner, :last_pipeline]) .preload([:owner, :last_pipeline])
present paginate(schedules), with: Entities::PipelineSchedule present paginate(schedules), with: Entities::Ci::PipelineSchedule
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a single pipeline schedule' do desc 'Get a single pipeline schedule' do
success Entities::PipelineScheduleDetails success Entities::Ci::PipelineScheduleDetails
end end
params do params do
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
end end
get ':id/pipeline_schedules/:pipeline_schedule_id' do get ':id/pipeline_schedules/:pipeline_schedule_id' do
present pipeline_schedule, with: Entities::PipelineScheduleDetails present pipeline_schedule, with: Entities::Ci::PipelineScheduleDetails
end end
desc 'Create a new pipeline schedule' do desc 'Create a new pipeline schedule' do
success Entities::PipelineScheduleDetails success Entities::Ci::PipelineScheduleDetails
end end
params do params do
requires :description, type: String, desc: 'The description of pipeline schedule' requires :description, type: String, desc: 'The description of pipeline schedule'
...@@ -57,14 +57,14 @@ module API ...@@ -57,14 +57,14 @@ module API
.execute .execute
if pipeline_schedule.persisted? if pipeline_schedule.persisted?
present pipeline_schedule, with: Entities::PipelineScheduleDetails present pipeline_schedule, with: Entities::Ci::PipelineScheduleDetails
else else
render_validation_error!(pipeline_schedule) render_validation_error!(pipeline_schedule)
end end
end end
desc 'Edit a pipeline schedule' do desc 'Edit a pipeline schedule' do
success Entities::PipelineScheduleDetails success Entities::Ci::PipelineScheduleDetails
end end
params do params do
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
...@@ -78,14 +78,14 @@ module API ...@@ -78,14 +78,14 @@ module API
authorize! :update_pipeline_schedule, pipeline_schedule authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule.update(declared_params(include_missing: false)) if pipeline_schedule.update(declared_params(include_missing: false))
present pipeline_schedule, with: Entities::PipelineScheduleDetails present pipeline_schedule, with: Entities::Ci::PipelineScheduleDetails
else else
render_validation_error!(pipeline_schedule) render_validation_error!(pipeline_schedule)
end end
end end
desc 'Take ownership of a pipeline schedule' do desc 'Take ownership of a pipeline schedule' do
success Entities::PipelineScheduleDetails success Entities::Ci::PipelineScheduleDetails
end end
params do params do
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
...@@ -94,14 +94,14 @@ module API ...@@ -94,14 +94,14 @@ module API
authorize! :update_pipeline_schedule, pipeline_schedule authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule.own!(current_user) if pipeline_schedule.own!(current_user)
present pipeline_schedule, with: Entities::PipelineScheduleDetails present pipeline_schedule, with: Entities::Ci::PipelineScheduleDetails
else else
render_validation_error!(pipeline_schedule) render_validation_error!(pipeline_schedule)
end end
end end
desc 'Delete a pipeline schedule' do desc 'Delete a pipeline schedule' do
success Entities::PipelineScheduleDetails success Entities::Ci::PipelineScheduleDetails
end end
params do params do
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
...@@ -132,7 +132,7 @@ module API ...@@ -132,7 +132,7 @@ module API
end end
desc 'Create a new pipeline schedule variable' do desc 'Create a new pipeline schedule variable' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
...@@ -146,14 +146,14 @@ module API ...@@ -146,14 +146,14 @@ module API
variable_params = declared_params(include_missing: false) variable_params = declared_params(include_missing: false)
variable = pipeline_schedule.variables.create(variable_params) variable = pipeline_schedule.variables.create(variable_params)
if variable.persisted? if variable.persisted?
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
else else
render_validation_error!(variable) render_validation_error!(variable)
end end
end end
desc 'Edit a pipeline schedule variable' do desc 'Edit a pipeline schedule variable' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
...@@ -165,14 +165,14 @@ module API ...@@ -165,14 +165,14 @@ module API
authorize! :update_pipeline_schedule, pipeline_schedule authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule_variable.update(declared_params(include_missing: false)) if pipeline_schedule_variable.update(declared_params(include_missing: false))
present pipeline_schedule_variable, with: Entities::Variable present pipeline_schedule_variable, with: Entities::Ci::Variable
else else
render_validation_error!(pipeline_schedule_variable) render_validation_error!(pipeline_schedule_variable)
end end
end end
desc 'Delete a pipeline schedule variable' do desc 'Delete a pipeline schedule variable' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
...@@ -182,7 +182,7 @@ module API ...@@ -182,7 +182,7 @@ module API
authorize! :admin_pipeline_schedule, pipeline_schedule authorize! :admin_pipeline_schedule, pipeline_schedule
status :accepted status :accepted
present pipeline_schedule_variable.destroy, with: Entities::Variable present pipeline_schedule_variable.destroy, with: Entities::Ci::Variable
end end
end end
......
...@@ -13,7 +13,7 @@ module API ...@@ -13,7 +13,7 @@ module API
resource :projects, requirements: ::API::API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :projects, requirements: ::API::API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get all Pipelines of the project' do desc 'Get all Pipelines of the project' do
detail 'This feature was introduced in GitLab 8.11.' detail 'This feature was introduced in GitLab 8.11.'
success Entities::PipelineBasic success Entities::Ci::PipelineBasic
end end
params do params do
use :pagination use :pagination
...@@ -38,12 +38,12 @@ module API ...@@ -38,12 +38,12 @@ module API
authorize! :read_build, user_project authorize! :read_build, user_project
pipelines = ::Ci::PipelinesFinder.new(user_project, current_user, params).execute pipelines = ::Ci::PipelinesFinder.new(user_project, current_user, params).execute
present paginate(pipelines), with: Entities::PipelineBasic present paginate(pipelines), with: Entities::Ci::PipelineBasic
end end
desc 'Create a new pipeline' do desc 'Create a new pipeline' do
detail 'This feature was introduced in GitLab 8.14' detail 'This feature was introduced in GitLab 8.14'
success Entities::Pipeline success Entities::Ci::Pipeline
end end
params do params do
requires :ref, type: String, desc: 'Reference' requires :ref, type: String, desc: 'Reference'
...@@ -64,7 +64,7 @@ module API ...@@ -64,7 +64,7 @@ module API
.execute(:api, ignore_skip_ci: true, save_on_errors: false) .execute(:api, ignore_skip_ci: true, save_on_errors: false)
if new_pipeline.persisted? if new_pipeline.persisted?
present new_pipeline, with: Entities::Pipeline present new_pipeline, with: Entities::Ci::Pipeline
else else
render_validation_error!(new_pipeline) render_validation_error!(new_pipeline)
end end
...@@ -72,7 +72,7 @@ module API ...@@ -72,7 +72,7 @@ module API
desc 'Gets a the latest pipeline for the project branch' do desc 'Gets a the latest pipeline for the project branch' do
detail 'This feature was introduced in GitLab 12.3' detail 'This feature was introduced in GitLab 12.3'
success Entities::Pipeline success Entities::Ci::Pipeline
end end
params do params do
optional :ref, type: String, desc: 'branch ref of pipeline' optional :ref, type: String, desc: 'branch ref of pipeline'
...@@ -80,12 +80,12 @@ module API ...@@ -80,12 +80,12 @@ module API
get ':id/pipelines/latest' do get ':id/pipelines/latest' do
authorize! :read_pipeline, latest_pipeline authorize! :read_pipeline, latest_pipeline
present latest_pipeline, with: Entities::Pipeline present latest_pipeline, with: Entities::Ci::Pipeline
end end
desc 'Gets a specific pipeline for the project' do desc 'Gets a specific pipeline for the project' do
detail 'This feature was introduced in GitLab 8.11' detail 'This feature was introduced in GitLab 8.11'
success Entities::Pipeline success Entities::Ci::Pipeline
end end
params do params do
requires :pipeline_id, type: Integer, desc: 'The pipeline ID' requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
...@@ -93,12 +93,12 @@ module API ...@@ -93,12 +93,12 @@ module API
get ':id/pipelines/:pipeline_id' do get ':id/pipelines/:pipeline_id' do
authorize! :read_pipeline, pipeline authorize! :read_pipeline, pipeline
present pipeline, with: Entities::Pipeline present pipeline, with: Entities::Ci::Pipeline
end end
desc 'Gets the variables for a given pipeline' do desc 'Gets the variables for a given pipeline' do
detail 'This feature was introduced in GitLab 11.11' detail 'This feature was introduced in GitLab 11.11'
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :pipeline_id, type: Integer, desc: 'The pipeline ID' requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
...@@ -106,7 +106,7 @@ module API ...@@ -106,7 +106,7 @@ module API
get ':id/pipelines/:pipeline_id/variables' do get ':id/pipelines/:pipeline_id/variables' do
authorize! :read_pipeline_variable, pipeline authorize! :read_pipeline_variable, pipeline
present pipeline.variables, with: Entities::Variable present pipeline.variables, with: Entities::Ci::Variable
end end
desc 'Gets the test report for a given pipeline' do desc 'Gets the test report for a given pipeline' do
...@@ -141,7 +141,7 @@ module API ...@@ -141,7 +141,7 @@ module API
desc 'Retry builds in the pipeline' do desc 'Retry builds in the pipeline' do
detail 'This feature was introduced in GitLab 8.11.' detail 'This feature was introduced in GitLab 8.11.'
success Entities::Pipeline success Entities::Ci::Pipeline
end end
params do params do
requires :pipeline_id, type: Integer, desc: 'The pipeline ID' requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
...@@ -151,12 +151,12 @@ module API ...@@ -151,12 +151,12 @@ module API
pipeline.retry_failed(current_user) pipeline.retry_failed(current_user)
present pipeline, with: Entities::Pipeline present pipeline, with: Entities::Ci::Pipeline
end end
desc 'Cancel all builds in the pipeline' do desc 'Cancel all builds in the pipeline' do
detail 'This feature was introduced in GitLab 8.11.' detail 'This feature was introduced in GitLab 8.11.'
success Entities::Pipeline success Entities::Ci::Pipeline
end end
params do params do
requires :pipeline_id, type: Integer, desc: 'The pipeline ID' requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
...@@ -167,7 +167,7 @@ module API ...@@ -167,7 +167,7 @@ module API
pipeline.cancel_running pipeline.cancel_running
status 200 status 200
present pipeline.reset, with: Entities::Pipeline present pipeline.reset, with: Entities::Ci::Pipeline
end end
end end
......
...@@ -111,7 +111,7 @@ module API ...@@ -111,7 +111,7 @@ module API
end end
desc 'List jobs running on a runner' do desc 'List jobs running on a runner' do
success Entities::JobBasicWithProject success Entities::Ci::JobBasicWithProject
end end
params do params do
requires :id, type: Integer, desc: 'The ID of the runner' requires :id, type: Integer, desc: 'The ID of the runner'
...@@ -126,7 +126,7 @@ module API ...@@ -126,7 +126,7 @@ module API
jobs = ::Ci::RunnerJobsFinder.new(runner, params).execute jobs = ::Ci::RunnerJobsFinder.new(runner, params).execute
present paginate(jobs), with: Entities::JobBasicWithProject present paginate(jobs), with: Entities::Ci::JobBasicWithProject
end end
end end
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
module API module API
module Entities module Entities
class Bridge < Entities::JobBasic module Ci
expose :downstream_pipeline, with: Entities::PipelineBasic class Bridge < JobBasic
expose :downstream_pipeline, with: ::API::Entities::Ci::PipelineBasic
end
end end
end end
end end
# frozen_string_literal: true
module API
module Entities
module Ci
class Job < JobBasic
# artifacts_file is included in job_artifacts, but kept for backward compatibility (remove in api/v5)
expose :artifacts_file, using: ::API::Entities::Ci::JobArtifactFile, if: -> (job, opts) { job.artifacts? }
expose :job_artifacts, as: :artifacts, using: ::API::Entities::Ci::JobArtifact
expose :runner, with: ::API::Entities::Runner
expose :artifacts_expire_at
end
end
end
end
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
module API module API
module Entities module Entities
class JobArtifact < Grape::Entity module Ci
expose :file_type, :size, :filename, :file_format class JobArtifact < Grape::Entity
expose :file_type, :size, :filename, :file_format
end
end end
end end
end end
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
module API module API
module Entities module Entities
class JobArtifactFile < Grape::Entity module Ci
expose :filename class JobArtifactFile < Grape::Entity
expose :cached_size, as: :size expose :filename
expose :cached_size, as: :size
end
end end
end end
end end
# frozen_string_literal: true
module API
module Entities
module Ci
class JobBasic < Grape::Entity
expose :id, :status, :stage, :name, :ref, :tag, :coverage, :allow_failure
expose :created_at, :started_at, :finished_at
expose :duration
expose :user, with: ::API::Entities::User
expose :commit, with: ::API::Entities::Commit
expose :pipeline, with: ::API::Entities::Ci::PipelineBasic
expose :web_url do |job, _options|
Gitlab::Routing.url_helpers.project_job_url(job.project, job)
end
end
end
end
end
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
module API module API
module Entities module Entities
class JobBasicWithProject < Entities::JobBasic module Ci
expose :project, with: Entities::ProjectIdentity class JobBasicWithProject < Entities::Ci::JobBasic
expose :project, with: Entities::ProjectIdentity
end
end end
end end
end end
# frozen_string_literal: true
module API
module Entities
module Ci
class Pipeline < PipelineBasic
expose :before_sha, :tag, :yaml_errors
expose :user, with: Entities::UserBasic
expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
expose :duration
expose :coverage
expose :detailed_status, using: DetailedStatusEntity do |pipeline, options|
pipeline.detailed_status(options[:current_user])
end
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Ci
class PipelineBasic < Grape::Entity
expose :id, :sha, :ref, :status
expose :created_at, :updated_at
expose :web_url do |pipeline, _options|
Gitlab::Routing.url_helpers.project_pipeline_url(pipeline.project, pipeline)
end
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Ci
class PipelineSchedule < Grape::Entity
expose :id
expose :description, :ref, :cron, :cron_timezone, :next_run_at, :active
expose :created_at, :updated_at
expose :owner, using: ::API::Entities::UserBasic
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Ci
class PipelineScheduleDetails < PipelineSchedule
expose :last_pipeline, using: ::API::Entities::Ci::PipelineBasic
expose :variables, using: ::API::Entities::Ci::Variable
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Ci
class Variable < Grape::Entity
expose :variable_type, :key, :value
expose :protected?, as: :protected, if: -> (entity, _) { entity.respond_to?(:protected?) }
expose :masked?, as: :masked, if: -> (entity, _) { entity.respond_to?(:masked?) }
expose :environment_scope, if: -> (entity, _) { entity.respond_to?(:environment_scope) }
end
end
end
end
...@@ -9,7 +9,7 @@ module API ...@@ -9,7 +9,7 @@ module API
expose :last_pipeline do |commit, options| expose :last_pipeline do |commit, options|
pipeline = commit.last_pipeline if can_read_pipeline? pipeline = commit.last_pipeline if can_read_pipeline?
::API::Entities::PipelineBasic.represent(pipeline, options) ::API::Entities::Ci::PipelineBasic.represent(pipeline, options)
end end
private private
......
...@@ -6,7 +6,7 @@ module API ...@@ -6,7 +6,7 @@ module API
expose :id, :iid, :ref, :sha, :created_at, :updated_at expose :id, :iid, :ref, :sha, :created_at, :updated_at
expose :user, using: Entities::UserBasic expose :user, using: Entities::UserBasic
expose :environment, using: Entities::EnvironmentBasic expose :environment, using: Entities::EnvironmentBasic
expose :deployable, using: Entities::Job expose :deployable, using: Entities::Ci::Job
expose :status expose :status
end end
end end
......
# frozen_string_literal: true
module API
module Entities
class Job < Entities::JobBasic
# artifacts_file is included in job_artifacts, but kept for backward compatibility (remove in api/v5)
expose :artifacts_file, using: Entities::JobArtifactFile, if: -> (job, opts) { job.artifacts? }
expose :job_artifacts, as: :artifacts, using: Entities::JobArtifact
expose :runner, with: Entities::Runner
expose :artifacts_expire_at
end
end
end
# frozen_string_literal: true
module API
module Entities
class JobBasic < Grape::Entity
expose :id, :status, :stage, :name, :ref, :tag, :coverage, :allow_failure
expose :created_at, :started_at, :finished_at
expose :duration
expose :user, with: Entities::User
expose :commit, with: Entities::Commit
expose :pipeline, with: Entities::PipelineBasic
expose :web_url do |job, _options|
Gitlab::Routing.url_helpers.project_job_url(job.project, job)
end
end
end
end
...@@ -5,7 +5,7 @@ module API ...@@ -5,7 +5,7 @@ module API
module JobRequest module JobRequest
class Dependency < Grape::Entity class Dependency < Grape::Entity
expose :id, :name, :token expose :id, :name, :token
expose :artifacts_file, using: Entities::JobArtifactFile, if: ->(job, _) { job.artifacts? } expose :artifacts_file, using: Entities::Ci::JobArtifactFile, if: ->(job, _) { job.artifacts? }
end end
end end
end end
......
...@@ -23,11 +23,11 @@ module API ...@@ -23,11 +23,11 @@ module API
merge_request.metrics&.first_deployed_to_production_at merge_request.metrics&.first_deployed_to_production_at
end end
expose :pipeline, using: Entities::PipelineBasic, if: -> (_, options) { build_available?(options) } do |merge_request, _options| expose :pipeline, using: Entities::Ci::PipelineBasic, if: -> (_, options) { build_available?(options) } do |merge_request, _options|
merge_request.metrics&.pipeline merge_request.metrics&.pipeline
end end
expose :head_pipeline, using: 'API::Entities::Pipeline', if: -> (_, options) do expose :head_pipeline, using: '::API::Entities::Ci::Pipeline', if: -> (_, options) do
Ability.allowed?(options[:current_user], :read_pipeline, options[:project]) Ability.allowed?(options[:current_user], :read_pipeline, options[:project])
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module API module API
module Entities module Entities
class Package < Grape::Entity class Package < Grape::Entity
class Pipeline < ::API::Entities::PipelineBasic class Pipeline < ::API::Entities::Ci::PipelineBasic
expose :user, using: ::API::Entities::UserBasic expose :user, using: ::API::Entities::UserBasic
end end
end end
......
# frozen_string_literal: true
module API
module Entities
class Pipeline < Entities::PipelineBasic
expose :before_sha, :tag, :yaml_errors
expose :user, with: Entities::UserBasic
expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
expose :duration
expose :coverage
expose :detailed_status, using: DetailedStatusEntity do |pipeline, options|
pipeline.detailed_status(options[:current_user])
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class PipelineBasic < Grape::Entity
expose :id, :sha, :ref, :status
expose :created_at, :updated_at
expose :web_url do |pipeline, _options|
Gitlab::Routing.url_helpers.project_pipeline_url(pipeline.project, pipeline)
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class PipelineSchedule < Grape::Entity
expose :id
expose :description, :ref, :cron, :cron_timezone, :next_run_at, :active
expose :created_at, :updated_at
expose :owner, using: Entities::UserBasic
end
end
end
# frozen_string_literal: true
module API
module Entities
class PipelineScheduleDetails < Entities::PipelineSchedule
expose :last_pipeline, using: Entities::PipelineBasic
expose :variables, using: Entities::Variable
end
end
end
# frozen_string_literal: true
module API
module Entities
class Variable < Grape::Entity
expose :variable_type, :key, :value
expose :protected?, as: :protected, if: -> (entity, _) { entity.respond_to?(:protected?) }
expose :masked?, as: :masked, if: -> (entity, _) { entity.respond_to?(:masked?) }
expose :environment_scope, if: -> (entity, _) { entity.respond_to?(:environment_scope) }
end
end
end
...@@ -13,18 +13,18 @@ module API ...@@ -13,18 +13,18 @@ module API
resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get group-level variables' do desc 'Get group-level variables' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
use :pagination use :pagination
end end
get ':id/variables' do get ':id/variables' do
variables = user_group.variables variables = user_group.variables
present paginate(variables), with: Entities::Variable present paginate(variables), with: Entities::Ci::Variable
end end
desc 'Get a specific variable from a group' do desc 'Get a specific variable from a group' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :key, type: String, desc: 'The key of the variable' requires :key, type: String, desc: 'The key of the variable'
...@@ -36,12 +36,12 @@ module API ...@@ -36,12 +36,12 @@ module API
break not_found!('GroupVariable') unless variable break not_found!('GroupVariable') unless variable
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
desc 'Create a new variable in a group' do desc 'Create a new variable in a group' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :key, type: String, desc: 'The key of the variable' requires :key, type: String, desc: 'The key of the variable'
...@@ -58,14 +58,14 @@ module API ...@@ -58,14 +58,14 @@ module API
).execute ).execute
if variable.valid? if variable.valid?
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
else else
render_validation_error!(variable) render_validation_error!(variable)
end end
end end
desc 'Update an existing variable from a group' do desc 'Update an existing variable from a group' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
optional :key, type: String, desc: 'The key of the variable' optional :key, type: String, desc: 'The key of the variable'
...@@ -83,7 +83,7 @@ module API ...@@ -83,7 +83,7 @@ module API
).execute ).execute
if variable.valid? if variable.valid?
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
else else
render_validation_error!(variable) render_validation_error!(variable)
end end
...@@ -93,7 +93,7 @@ module API ...@@ -93,7 +93,7 @@ module API
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing variable from a group' do desc 'Delete an existing variable from a group' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :key, type: String, desc: 'The key of the variable' requires :key, type: String, desc: 'The key of the variable'
......
...@@ -94,7 +94,7 @@ module API ...@@ -94,7 +94,7 @@ module API
end end
desc 'Keep the artifacts to prevent them from being deleted' do desc 'Keep the artifacts to prevent them from being deleted' do
success Entities::Job success ::API::Entities::Ci::Job
end end
params do params do
requires :job_id, type: Integer, desc: 'The ID of a job' requires :job_id, type: Integer, desc: 'The ID of a job'
...@@ -109,7 +109,7 @@ module API ...@@ -109,7 +109,7 @@ module API
build.keep_artifacts! build.keep_artifacts!
status 200 status 200
present build, with: Entities::Job present build, with: ::API::Entities::Ci::Job
end end
desc 'Delete the artifacts files from a job' do desc 'Delete the artifacts files from a job' do
......
...@@ -30,7 +30,7 @@ module API ...@@ -30,7 +30,7 @@ module API
end end
desc 'Get a projects jobs' do desc 'Get a projects jobs' do
success Entities::Job success Entities::Ci::Job
end end
params do params do
use :optional_scope use :optional_scope
...@@ -44,12 +44,12 @@ module API ...@@ -44,12 +44,12 @@ module API
builds = filter_builds(builds, params[:scope]) builds = filter_builds(builds, params[:scope])
builds = builds.preload(:user, :job_artifacts_archive, :job_artifacts, :runner, pipeline: :project) builds = builds.preload(:user, :job_artifacts_archive, :job_artifacts, :runner, pipeline: :project)
present paginate(builds), with: Entities::Job present paginate(builds), with: Entities::Ci::Job
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
desc 'Get pipeline jobs' do desc 'Get pipeline jobs' do
success Entities::Job success Entities::Ci::Job
end end
params do params do
requires :pipeline_id, type: Integer, desc: 'The pipeline ID' requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
...@@ -66,12 +66,12 @@ module API ...@@ -66,12 +66,12 @@ module API
builds = filter_builds(builds, params[:scope]) builds = filter_builds(builds, params[:scope])
builds = builds.preload(:job_artifacts_archive, :job_artifacts, project: [:namespace]) builds = builds.preload(:job_artifacts_archive, :job_artifacts, project: [:namespace])
present paginate(builds), with: Entities::Job present paginate(builds), with: Entities::Ci::Job
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
desc 'Get pipeline bridge jobs' do desc 'Get pipeline bridge jobs' do
success Entities::Bridge success ::API::Entities::Ci::Bridge
end end
params do params do
requires :pipeline_id, type: Integer, desc: 'The pipeline ID' requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
...@@ -92,12 +92,12 @@ module API ...@@ -92,12 +92,12 @@ module API
project: [:namespace] project: [:namespace]
) )
present paginate(bridges), with: Entities::Bridge present paginate(bridges), with: ::API::Entities::Ci::Bridge
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
desc 'Get a specific job of a project' do desc 'Get a specific job of a project' do
success Entities::Job success Entities::Ci::Job
end end
params do params do
requires :job_id, type: Integer, desc: 'The ID of a job' requires :job_id, type: Integer, desc: 'The ID of a job'
...@@ -107,7 +107,7 @@ module API ...@@ -107,7 +107,7 @@ module API
build = find_build!(params[:job_id]) build = find_build!(params[:job_id])
present build, with: Entities::Job present build, with: Entities::Ci::Job
end end
# TODO: We should use `present_disk_file!` and leave this implementation for backward compatibility (when build trace # TODO: We should use `present_disk_file!` and leave this implementation for backward compatibility (when build trace
...@@ -131,7 +131,7 @@ module API ...@@ -131,7 +131,7 @@ module API
end end
desc 'Cancel a specific job of a project' do desc 'Cancel a specific job of a project' do
success Entities::Job success Entities::Ci::Job
end end
params do params do
requires :job_id, type: Integer, desc: 'The ID of a job' requires :job_id, type: Integer, desc: 'The ID of a job'
...@@ -144,11 +144,11 @@ module API ...@@ -144,11 +144,11 @@ module API
build.cancel build.cancel
present build, with: Entities::Job present build, with: Entities::Ci::Job
end end
desc 'Retry a specific build of a project' do desc 'Retry a specific build of a project' do
success Entities::Job success Entities::Ci::Job
end end
params do params do
requires :job_id, type: Integer, desc: 'The ID of a build' requires :job_id, type: Integer, desc: 'The ID of a build'
...@@ -162,11 +162,11 @@ module API ...@@ -162,11 +162,11 @@ module API
build = ::Ci::Build.retry(build, current_user) build = ::Ci::Build.retry(build, current_user)
present build, with: Entities::Job present build, with: Entities::Ci::Job
end end
desc 'Erase job (remove artifacts and the trace)' do desc 'Erase job (remove artifacts and the trace)' do
success Entities::Job success Entities::Ci::Job
end end
params do params do
requires :job_id, type: Integer, desc: 'The ID of a build' requires :job_id, type: Integer, desc: 'The ID of a build'
...@@ -179,11 +179,11 @@ module API ...@@ -179,11 +179,11 @@ module API
break forbidden!('Job is not erasable!') unless build.erasable? break forbidden!('Job is not erasable!') unless build.erasable?
build.erase(erased_by: current_user) build.erase(erased_by: current_user)
present build, with: Entities::Job present build, with: Entities::Ci::Job
end end
desc 'Trigger a actionable job (manual, delayed, etc)' do desc 'Trigger a actionable job (manual, delayed, etc)' do
success Entities::Job success Entities::Ci::Job
detail 'This feature was added in GitLab 8.11' detail 'This feature was added in GitLab 8.11'
end end
params do params do
...@@ -200,7 +200,7 @@ module API ...@@ -200,7 +200,7 @@ module API
build.play(current_user) build.play(current_user)
status 200 status 200
present build, with: Entities::Job present build, with: Entities::Ci::Job
end end
end end
......
...@@ -352,16 +352,16 @@ module API ...@@ -352,16 +352,16 @@ module API
end end
desc 'Get the merge request pipelines' do desc 'Get the merge request pipelines' do
success Entities::PipelineBasic success Entities::Ci::PipelineBasic
end end
get ':id/merge_requests/:merge_request_iid/pipelines' do get ':id/merge_requests/:merge_request_iid/pipelines' do
pipelines = merge_request_pipelines_with_access pipelines = merge_request_pipelines_with_access
present paginate(pipelines), with: Entities::PipelineBasic present paginate(pipelines), with: Entities::Ci::PipelineBasic
end end
desc 'Create a pipeline for merge request' do desc 'Create a pipeline for merge request' do
success Entities::Pipeline success ::API::Entities::Ci::Pipeline
end end
post ':id/merge_requests/:merge_request_iid/pipelines' do post ':id/merge_requests/:merge_request_iid/pipelines' do
pipeline = ::MergeRequests::CreatePipelineService pipeline = ::MergeRequests::CreatePipelineService
...@@ -372,7 +372,7 @@ module API ...@@ -372,7 +372,7 @@ module API
not_allowed! not_allowed!
elsif pipeline.persisted? elsif pipeline.persisted?
status :ok status :ok
present pipeline, with: Entities::Pipeline present pipeline, with: ::API::Entities::Ci::Pipeline
else else
render_validation_error!(pipeline) render_validation_error!(pipeline)
end end
......
...@@ -11,7 +11,7 @@ module API ...@@ -11,7 +11,7 @@ module API
end end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Trigger a GitLab project pipeline' do desc 'Trigger a GitLab project pipeline' do
success Entities::Pipeline success Entities::Ci::Pipeline
end end
params do params do
requires :ref, type: String, desc: 'The commit sha or name of a branch or tag', allow_blank: false requires :ref, type: String, desc: 'The commit sha or name of a branch or tag', allow_blank: false
...@@ -38,7 +38,7 @@ module API ...@@ -38,7 +38,7 @@ module API
if result[:http_status] if result[:http_status]
render_api_error!(result[:message], result[:http_status]) render_api_error!(result[:message], result[:http_status])
else else
present result[:pipeline], with: Entities::Pipeline present result[:pipeline], with: Entities::Ci::Pipeline
end end
end end
......
...@@ -30,18 +30,18 @@ module API ...@@ -30,18 +30,18 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get project variables' do desc 'Get project variables' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
use :pagination use :pagination
end end
get ':id/variables' do get ':id/variables' do
variables = user_project.variables variables = user_project.variables
present paginate(variables), with: Entities::Variable present paginate(variables), with: Entities::Ci::Variable
end end
desc 'Get a specific variable from a project' do desc 'Get a specific variable from a project' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :key, type: String, desc: 'The key of the variable' requires :key, type: String, desc: 'The key of the variable'
...@@ -51,12 +51,12 @@ module API ...@@ -51,12 +51,12 @@ module API
variable = find_variable(params) variable = find_variable(params)
not_found!('Variable') unless variable not_found!('Variable') unless variable
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
desc 'Create a new variable in a project' do desc 'Create a new variable in a project' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :key, type: String, desc: 'The key of the variable' requires :key, type: String, desc: 'The key of the variable'
...@@ -73,14 +73,14 @@ module API ...@@ -73,14 +73,14 @@ module API
variable = user_project.variables.create(variable_params) variable = user_project.variables.create(variable_params)
if variable.valid? if variable.valid?
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
else else
render_validation_error!(variable) render_validation_error!(variable)
end end
end end
desc 'Update an existing variable from a project' do desc 'Update an existing variable from a project' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
optional :key, type: String, desc: 'The key of the variable' optional :key, type: String, desc: 'The key of the variable'
...@@ -100,7 +100,7 @@ module API ...@@ -100,7 +100,7 @@ module API
variable_params = filter_variable_parameters(variable_params) variable_params = filter_variable_parameters(variable_params)
if variable.update(variable_params) if variable.update(variable_params)
present variable, with: Entities::Variable present variable, with: Entities::Ci::Variable
else else
render_validation_error!(variable) render_validation_error!(variable)
end end
...@@ -108,7 +108,7 @@ module API ...@@ -108,7 +108,7 @@ module API
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing variable from a project' do desc 'Delete an existing variable from a project' do
success Entities::Variable success Entities::Ci::Variable
end end
params do params do
requires :key, type: String, desc: 'The key of the variable' requires :key, type: String, desc: 'The key of the variable'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment