Commit a1767c8e authored by Nick Thomas's avatar Nick Thomas

Merge branch '273602-move-lib-entities-to-ci-namespace' into 'master'

Move Entities::JobRequest under Ci namespace

See merge request gitlab-org/gitlab!66078
parents 73fbacef 81299210
...@@ -2201,8 +2201,8 @@ Cop/UserAdmin: ...@@ -2201,8 +2201,8 @@ Cop/UserAdmin:
- 'ee/lib/ee/gitlab/git_access.rb' - 'ee/lib/ee/gitlab/git_access.rb'
- 'lib/api/award_emoji.rb' - 'lib/api/award_emoji.rb'
- 'lib/api/ci/runners.rb' - 'lib/api/ci/runners.rb'
- 'lib/api/entities/runner_details.rb' - 'lib/api/entities/ci/runner_details.rb'
- 'lib/api/entities/user_safe.rb' - 'lib/api/entities/ci/user_safe.rb'
- 'lib/api/groups.rb' - 'lib/api/groups.rb'
- 'lib/api/helpers.rb' - 'lib/api/helpers.rb'
- 'lib/api/personal_access_tokens.rb' - 'lib/api/personal_access_tokens.rb'
......
...@@ -209,7 +209,7 @@ module Ci ...@@ -209,7 +209,7 @@ module Ci
# We need to use the presenter here because Gitaly calls in the presenter # We need to use the presenter here because Gitaly calls in the presenter
# may fail, and we need to ensure the response has been generated. # may fail, and we need to ensure the response has been generated.
presented_build = ::Ci::BuildRunnerPresenter.new(build) # rubocop:disable CodeReuse/Presenter presented_build = ::Ci::BuildRunnerPresenter.new(build) # rubocop:disable CodeReuse/Presenter
build_json = ::API::Entities::JobRequest::Response.new(presented_build).to_json build_json = ::API::Entities::Ci::JobRequest::Response.new(presented_build).to_json
Result.new(build, build_json, true) Result.new(build, build_json, true)
end end
......
...@@ -3,12 +3,14 @@ ...@@ -3,12 +3,14 @@
module EE module EE
module API module API
module Entities module Entities
module JobRequest module Ci
module Response module JobRequest
extend ActiveSupport::Concern module Response
extend ActiveSupport::Concern
prepended do prepended do
expose :secrets_configuration, as: :secrets, if: -> (build, _) { build.ci_secrets_management_available? } expose :secrets_configuration, as: :secrets, if: -> (build, _) { build.ci_secrets_management_available? }
end
end end
end end
end end
......
...@@ -22,7 +22,7 @@ module EE ...@@ -22,7 +22,7 @@ module EE
{ {
allowed_agents: ::API::Entities::Clusters::Agent.represent(allowed_agents), allowed_agents: ::API::Entities::Clusters::Agent.represent(allowed_agents),
job: ::API::Entities::JobRequest::JobInfo.represent(current_authenticated_job), job: ::API::Entities::Ci::JobRequest::JobInfo.represent(current_authenticated_job),
pipeline: ::API::Entities::Ci::PipelineBasic.represent(pipeline), pipeline: ::API::Entities::Ci::PipelineBasic.represent(pipeline),
project: ::API::Entities::ProjectIdentity.represent(project), project: ::API::Entities::ProjectIdentity.represent(project),
user: ::API::Entities::UserBasic.represent(current_user) user: ::API::Entities::UserBasic.represent(current_user)
......
...@@ -11,7 +11,7 @@ module API ...@@ -11,7 +11,7 @@ module API
resource :runners do resource :runners do
desc 'Registers a new Runner' do desc 'Registers a new Runner' do
success Entities::RunnerRegistrationDetails success Entities::Ci::RunnerRegistrationDetails
http_codes [[201, 'Runner was created'], [403, 'Forbidden']] http_codes [[201, 'Runner was created'], [403, 'Forbidden']]
end end
params do params do
...@@ -47,7 +47,7 @@ module API ...@@ -47,7 +47,7 @@ module API
@runner = ::Ci::Runner.create(attributes) @runner = ::Ci::Runner.create(attributes)
if @runner.persisted? if @runner.persisted?
present @runner, with: Entities::RunnerRegistrationDetails present @runner, with: Entities::Ci::RunnerRegistrationDetails
else else
render_validation_error!(@runner) render_validation_error!(@runner)
end end
...@@ -82,7 +82,7 @@ module API ...@@ -82,7 +82,7 @@ module API
before { set_application_context } before { set_application_context }
desc 'Request a job' do desc 'Request a job' do
success Entities::JobRequest::Response success Entities::Ci::JobRequest::Response
http_codes [[201, 'Job was scheduled'], http_codes [[201, 'Job was scheduled'],
[204, 'No job for Runner'], [204, 'No job for Runner'],
[403, 'Forbidden']] [403, 'Forbidden']]
...@@ -267,7 +267,7 @@ module API ...@@ -267,7 +267,7 @@ module API
end end
desc 'Upload artifacts for job' do desc 'Upload artifacts for job' do
success Entities::JobRequest::Response success Entities::Ci::JobRequest::Response
http_codes [[201, 'Artifact uploaded'], http_codes [[201, 'Artifact uploaded'],
[400, 'Bad request'], [400, 'Bad request'],
[403, 'Forbidden'], [403, 'Forbidden'],
......
...@@ -11,7 +11,7 @@ module API ...@@ -11,7 +11,7 @@ module API
resource :runners do resource :runners do
desc 'Get runners available for user' do desc 'Get runners available for user' do
success Entities::Runner success Entities::Ci::Runner
end end
params do params do
optional :scope, type: String, values: ::Ci::Runner::AVAILABLE_STATUSES, optional :scope, type: String, values: ::Ci::Runner::AVAILABLE_STATUSES,
...@@ -30,11 +30,11 @@ module API ...@@ -30,11 +30,11 @@ module API
runners = filter_runners(runners, params[:status], allowed_scopes: ::Ci::Runner::AVAILABLE_STATUSES) runners = filter_runners(runners, params[:status], allowed_scopes: ::Ci::Runner::AVAILABLE_STATUSES)
runners = runners.tagged_with(params[:tag_list]) if params[:tag_list] runners = runners.tagged_with(params[:tag_list]) if params[:tag_list]
present paginate(runners), with: Entities::Runner present paginate(runners), with: Entities::Ci::Runner
end end
desc 'Get all runners - shared and specific' do desc 'Get all runners - shared and specific' do
success Entities::Runner success Entities::Ci::Runner
end end
params do params do
optional :scope, type: String, values: ::Ci::Runner::AVAILABLE_SCOPES, optional :scope, type: String, values: ::Ci::Runner::AVAILABLE_SCOPES,
...@@ -55,11 +55,11 @@ module API ...@@ -55,11 +55,11 @@ module API
runners = filter_runners(runners, params[:status], allowed_scopes: ::Ci::Runner::AVAILABLE_STATUSES) runners = filter_runners(runners, params[:status], allowed_scopes: ::Ci::Runner::AVAILABLE_STATUSES)
runners = runners.tagged_with(params[:tag_list]) if params[:tag_list] runners = runners.tagged_with(params[:tag_list]) if params[:tag_list]
present paginate(runners), with: Entities::Runner present paginate(runners), with: Entities::Ci::Runner
end end
desc "Get runner's details" do desc "Get runner's details" do
success Entities::RunnerDetails success Entities::Ci::RunnerDetails
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'
...@@ -68,11 +68,11 @@ module API ...@@ -68,11 +68,11 @@ module API
runner = get_runner(params[:id]) runner = get_runner(params[:id])
authenticate_show_runner!(runner) authenticate_show_runner!(runner)
present runner, with: Entities::RunnerDetails, current_user: current_user present runner, with: Entities::Ci::RunnerDetails, current_user: current_user
end end
desc "Update runner's details" do desc "Update runner's details" do
success Entities::RunnerDetails success Entities::Ci::RunnerDetails
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'
...@@ -92,14 +92,14 @@ module API ...@@ -92,14 +92,14 @@ module API
update_service = ::Ci::UpdateRunnerService.new(runner) update_service = ::Ci::UpdateRunnerService.new(runner)
if update_service.update(declared_params(include_missing: false)) if update_service.update(declared_params(include_missing: false))
present runner, with: Entities::RunnerDetails, current_user: current_user present runner, with: Entities::Ci::RunnerDetails, current_user: current_user
else else
render_validation_error!(runner) render_validation_error!(runner)
end end
end end
desc 'Remove a runner' do desc 'Remove a runner' do
success Entities::Runner success Entities::Ci::Runner
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'
...@@ -139,7 +139,7 @@ module API ...@@ -139,7 +139,7 @@ module API
before { authorize_admin_project } before { authorize_admin_project }
desc 'Get runners available for project' do desc 'Get runners available for project' do
success Entities::Runner success Entities::Ci::Runner
end end
params do params do
optional :scope, type: String, values: ::Ci::Runner::AVAILABLE_SCOPES, optional :scope, type: String, values: ::Ci::Runner::AVAILABLE_SCOPES,
...@@ -158,11 +158,11 @@ module API ...@@ -158,11 +158,11 @@ module API
runners = filter_runners(runners, params[:scope]) runners = filter_runners(runners, params[:scope])
runners = apply_filter(runners, params) runners = apply_filter(runners, params)
present paginate(runners), with: Entities::Runner present paginate(runners), with: Entities::Ci::Runner
end end
desc 'Enable a runner for a project' do desc 'Enable a runner for a project' do
success Entities::Runner success Entities::Ci::Runner
end end
params do params do
requires :runner_id, type: Integer, desc: 'The ID of the runner' requires :runner_id, type: Integer, desc: 'The ID of the runner'
...@@ -172,14 +172,14 @@ module API ...@@ -172,14 +172,14 @@ module API
authenticate_enable_runner!(runner) authenticate_enable_runner!(runner)
if runner.assign_to(user_project) if runner.assign_to(user_project)
present runner, with: Entities::Runner present runner, with: Entities::Ci::Runner
else else
render_validation_error!(runner) render_validation_error!(runner)
end end
end end
desc "Disable project's runner" do desc "Disable project's runner" do
success Entities::Runner success Entities::Ci::Runner
end end
params do params do
requires :runner_id, type: Integer, desc: 'The ID of the runner' requires :runner_id, type: Integer, desc: 'The ID of the runner'
...@@ -204,7 +204,7 @@ module API ...@@ -204,7 +204,7 @@ module API
before { authorize_admin_group } before { authorize_admin_group }
desc 'Get runners available for group' do desc 'Get runners available for group' do
success Entities::Runner success Entities::Ci::Runner
end end
params do params do
optional :type, type: String, values: ::Ci::Runner::AVAILABLE_TYPES, optional :type, type: String, values: ::Ci::Runner::AVAILABLE_TYPES,
...@@ -218,7 +218,7 @@ module API ...@@ -218,7 +218,7 @@ module API
runners = ::Ci::Runner.belonging_to_group(user_group.id, include_ancestors: true) runners = ::Ci::Runner.belonging_to_group(user_group.id, include_ancestors: true)
runners = apply_filter(runners, params) runners = apply_filter(runners, params)
present paginate(runners), with: Entities::Runner present paginate(runners), with: Entities::Ci::Runner
end end
end end
......
...@@ -7,7 +7,7 @@ module API ...@@ -7,7 +7,7 @@ module API
# artifacts_file is included in job_artifacts, but kept for backward compatibility (remove in api/v5) # 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 :artifacts_file, using: ::API::Entities::Ci::JobArtifactFile, if: -> (job, opts) { job.artifacts? }
expose :job_artifacts, as: :artifacts, using: ::API::Entities::Ci::JobArtifact expose :job_artifacts, as: :artifacts, using: ::API::Entities::Ci::JobArtifact
expose :runner, with: ::API::Entities::Runner expose :runner, with: ::API::Entities::Ci::Runner
expose :artifacts_expire_at expose :artifacts_expire_at
expose :tag_list do |job| expose :tag_list do |job|
job.tags.map(&:name).sort job.tags.map(&:name).sort
......
# frozen_string_literal: true
module API
module Entities
module Ci
module JobRequest
class Artifacts < Grape::Entity
expose :name
expose :untracked
expose :paths
expose :exclude, expose_nil: false
expose :when
expose :expire_in
expose :artifact_type
expose :artifact_format
end
end
end
end
end
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
module API module API
module Entities module Entities
module JobRequest module Ci
class JobInfo < Grape::Entity module JobRequest
expose :id, :name, :stage class Cache < Grape::Entity
expose :project_id, :project_name expose :key, :untracked, :paths, :policy, :when
end
end end
end end
end end
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
module API module API
module Entities module Entities
module JobRequest module Ci
class Credentials < Grape::Entity module JobRequest
expose :type, :url, :username, :password class Credentials < Grape::Entity
expose :type, :url, :username, :password
end
end end
end end
end end
......
# frozen_string_literal: true
module API
module Entities
module Ci
module JobRequest
class Dependency < Grape::Entity
expose :id, :name, :token
expose :artifacts_file, using: Entities::Ci::JobArtifactFile, if: ->(job, _) { job.artifacts? }
end
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Ci
module JobRequest
class GitInfo < Grape::Entity
expose :repo_url, :ref, :sha, :before_sha
expose :ref_type
expose :refspecs
expose :git_depth, as: :depth
end
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Ci
module JobRequest
class Image < Grape::Entity
expose :name, :entrypoint
expose :ports, using: Entities::Ci::JobRequest::Port
end
end
end
end
end
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
module API module API
module Entities module Entities
module JobRequest module Ci
class Image < Grape::Entity module JobRequest
expose :name, :entrypoint class JobInfo < Grape::Entity
expose :ports, using: Entities::JobRequest::Port expose :id, :name, :stage
expose :project_id, :project_name
end
end end
end end
end end
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
module API module API
module Entities module Entities
module JobRequest module Ci
class Service < Entities::JobRequest::Image module JobRequest
expose :alias, :command class Port < Grape::Entity
expose :number, :protocol, :name
end
end end
end end
end end
......
# frozen_string_literal: true
module API
module Entities
module Ci
module JobRequest
class Response < Grape::Entity
expose :id
expose :token
expose :allow_git_fetch
expose :job_info, using: Entities::Ci::JobRequest::JobInfo do |model|
model
end
expose :git_info, using: Entities::Ci::JobRequest::GitInfo do |model|
model
end
expose :runner_info, using: Entities::Ci::JobRequest::RunnerInfo do |model|
model
end
expose :runner_variables, as: :variables
expose :steps, using: Entities::Ci::JobRequest::Step
expose :image, using: Entities::Ci::JobRequest::Image
expose :services, using: Entities::Ci::JobRequest::Service
expose :artifacts, using: Entities::Ci::JobRequest::Artifacts
expose :cache, using: Entities::Ci::JobRequest::Cache
expose :credentials, using: Entities::Ci::JobRequest::Credentials
expose :all_dependencies, as: :dependencies, using: Entities::Ci::JobRequest::Dependency
expose :features
end
end
end
end
end
API::Entities::Ci::JobRequest::Response.prepend_mod_with('API::Entities::Ci::JobRequest::Response')
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
module API module API
module Entities module Entities
module JobRequest module Ci
class RunnerInfo < Grape::Entity module JobRequest
expose :metadata_timeout, as: :timeout class RunnerInfo < Grape::Entity
expose :runner_session_url expose :metadata_timeout, as: :timeout
expose :runner_session_url
end
end end
end end
end end
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
module API module API
module Entities module Entities
module JobRequest module Ci
class Cache < Grape::Entity module JobRequest
expose :key, :untracked, :paths, :policy, :when class Service < Entities::Ci::JobRequest::Image
expose :alias, :command
end
end end
end end
end end
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
module API module API
module Entities module Entities
module JobRequest module Ci
class Step < Grape::Entity module JobRequest
expose :name, :script, :timeout, :when, :allow_failure class Step < Grape::Entity
expose :name, :script, :timeout, :when, :allow_failure
end
end end
end end
end end
......
# frozen_string_literal: true
module API
module Entities
module Ci
class Runner < Grape::Entity
expose :id
expose :description
expose :ip_address
expose :active
expose :instance_type?, as: :is_shared
expose :runner_type
expose :name
expose :online?, as: :online
expose :status
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module Ci
class RunnerDetails < Runner
expose :tag_list
expose :run_untagged
expose :locked
expose :maximum_timeout
expose :access_level
expose :version, :revision, :platform, :architecture
expose :contacted_at
# rubocop: disable CodeReuse/ActiveRecord
expose :projects, with: Entities::BasicProjectDetails do |runner, options|
if options[:current_user].admin? # rubocop: disable Cop/UserAdmin
runner.projects
else
options[:current_user].authorized_projects.where(id: runner.projects)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
expose :groups, with: Entities::BasicGroupDetails do |runner, options|
if options[:current_user].admin? # rubocop: disable Cop/UserAdmin
runner.groups
else
options[:current_user].authorized_groups.where(id: runner.groups)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
module API module API
module Entities module Entities
module JobRequest module Ci
class Port < Grape::Entity class RunnerRegistrationDetails < Grape::Entity
expose :number, :protocol, :name expose :id, :token
end end
end end
end end
......
# frozen_string_literal: true
module API
module Entities
module JobRequest
class Artifacts < Grape::Entity
expose :name
expose :untracked
expose :paths
expose :exclude, expose_nil: false
expose :when
expose :expire_in
expose :artifact_type
expose :artifact_format
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module JobRequest
class Dependency < Grape::Entity
expose :id, :name, :token
expose :artifacts_file, using: Entities::Ci::JobArtifactFile, if: ->(job, _) { job.artifacts? }
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module JobRequest
class GitInfo < Grape::Entity
expose :repo_url, :ref, :sha, :before_sha
expose :ref_type
expose :refspecs
expose :git_depth, as: :depth
end
end
end
end
# frozen_string_literal: true
module API
module Entities
module JobRequest
class Response < Grape::Entity
expose :id
expose :token
expose :allow_git_fetch
expose :job_info, using: Entities::JobRequest::JobInfo do |model|
model
end
expose :git_info, using: Entities::JobRequest::GitInfo do |model|
model
end
expose :runner_info, using: Entities::JobRequest::RunnerInfo do |model|
model
end
expose :runner_variables, as: :variables
expose :steps, using: Entities::JobRequest::Step
expose :image, using: Entities::JobRequest::Image
expose :services, using: Entities::JobRequest::Service
expose :artifacts, using: Entities::JobRequest::Artifacts
expose :cache, using: Entities::JobRequest::Cache
expose :credentials, using: Entities::JobRequest::Credentials
expose :all_dependencies, as: :dependencies, using: Entities::JobRequest::Dependency
expose :features
end
end
end
end
API::Entities::JobRequest::Response.prepend_mod_with('API::Entities::JobRequest::Response')
# frozen_string_literal: true
module API
module Entities
class Runner < Grape::Entity
expose :id
expose :description
expose :ip_address
expose :active
expose :instance_type?, as: :is_shared
expose :runner_type
expose :name
expose :online?, as: :online
expose :status
end
end
end
# frozen_string_literal: true
module API
module Entities
class RunnerDetails < Runner
expose :tag_list
expose :run_untagged
expose :locked
expose :maximum_timeout
expose :access_level
expose :version, :revision, :platform, :architecture
expose :contacted_at
# rubocop: disable CodeReuse/ActiveRecord
expose :projects, with: Entities::BasicProjectDetails do |runner, options|
if options[:current_user].admin?
runner.projects
else
options[:current_user].authorized_projects.where(id: runner.projects)
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
expose :groups, with: Entities::BasicGroupDetails do |runner, options|
if options[:current_user].admin?
runner.groups
else
options[:current_user].authorized_groups.where(id: runner.groups)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
# frozen_string_literal: true
module API
module Entities
class RunnerRegistrationDetails < Grape::Entity
expose :id, :token
end
end
end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe API::Entities::JobRequest::Image do RSpec.describe API::Entities::Ci::JobRequest::Image do
let(:ports) { [{ number: 80, protocol: 'http', name: 'name' }]} let(:ports) { [{ number: 80, protocol: 'http', name: 'name' }]}
let(:image) { double(name: 'image_name', entrypoint: ['foo'], ports: ports)} let(:image) { double(name: 'image_name', entrypoint: ['foo'], ports: ports)}
let(:entity) { described_class.new(image) } let(:entity) { described_class.new(image) }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ::API::Entities::JobRequest::Port do RSpec.describe ::API::Entities::Ci::JobRequest::Port do
let(:port) { double(number: 80, protocol: 'http', name: 'name')} let(:port) { double(number: 80, protocol: 'http', name: 'name')}
let(:entity) { described_class.new(port) } let(:entity) { described_class.new(port) }
......
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