Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
parent
d0356412df
commit
78214bf742
8 changed files with 89 additions and 54 deletions
5
changelogs/unreleased/refactoring-entities-file-9.yml
Normal file
5
changelogs/unreleased/refactoring-entities-file-9.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Separate protected and issuable entities into own class files
|
||||
merge_request: 24221
|
||||
author: Rajendra Kadam
|
||||
type: added
|
|
@ -128,60 +128,6 @@ module API
|
|||
end
|
||||
end
|
||||
|
||||
class IssuableEntity < Grape::Entity
|
||||
expose :id, :iid
|
||||
expose(:project_id) { |entity| entity&.project.try(:id) }
|
||||
expose :title, :description
|
||||
expose :state, :created_at, :updated_at
|
||||
|
||||
# Avoids an N+1 query when metadata is included
|
||||
def issuable_metadata(subject, options, method, args = nil)
|
||||
cached_subject = options.dig(:issuable_metadata, subject.id)
|
||||
(cached_subject || subject).public_send(method, *args) # rubocop: disable GitlabSecurity/PublicSend
|
||||
end
|
||||
end
|
||||
|
||||
class IssuableReferences < Grape::Entity
|
||||
expose :short do |issuable|
|
||||
issuable.to_reference
|
||||
end
|
||||
|
||||
expose :relative do |issuable, options|
|
||||
issuable.to_reference(options[:group] || options[:project])
|
||||
end
|
||||
|
||||
expose :full do |issuable|
|
||||
issuable.to_reference(full: true)
|
||||
end
|
||||
end
|
||||
|
||||
class Diff < Grape::Entity
|
||||
expose :old_path, :new_path, :a_mode, :b_mode
|
||||
expose :new_file?, as: :new_file
|
||||
expose :renamed_file?, as: :renamed_file
|
||||
expose :deleted_file?, as: :deleted_file
|
||||
expose :json_safe_diff, as: :diff
|
||||
end
|
||||
|
||||
class ProtectedRefAccess < Grape::Entity
|
||||
expose :access_level
|
||||
expose :access_level_description do |protected_ref_access|
|
||||
protected_ref_access.humanize
|
||||
end
|
||||
end
|
||||
|
||||
class ProtectedBranch < Grape::Entity
|
||||
expose :id
|
||||
expose :name
|
||||
expose :push_access_levels, using: Entities::ProtectedRefAccess
|
||||
expose :merge_access_levels, using: Entities::ProtectedRefAccess
|
||||
end
|
||||
|
||||
class ProtectedTag < Grape::Entity
|
||||
expose :name
|
||||
expose :create_access_levels, using: Entities::ProtectedRefAccess
|
||||
end
|
||||
|
||||
class Milestone < Grape::Entity
|
||||
expose :id, :iid
|
||||
expose :project_id, if: -> (entity, options) { entity&.project_id }
|
||||
|
|
13
lib/api/entities/diff.rb
Normal file
13
lib/api/entities/diff.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module API
|
||||
module Entities
|
||||
class Diff < Grape::Entity
|
||||
expose :old_path, :new_path, :a_mode, :b_mode
|
||||
expose :new_file?, as: :new_file
|
||||
expose :renamed_file?, as: :renamed_file
|
||||
expose :deleted_file?, as: :deleted_file
|
||||
expose :json_safe_diff, as: :diff
|
||||
end
|
||||
end
|
||||
end
|
18
lib/api/entities/issuable_entity.rb
Normal file
18
lib/api/entities/issuable_entity.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module API
|
||||
module Entities
|
||||
class IssuableEntity < Grape::Entity
|
||||
expose :id, :iid
|
||||
expose(:project_id) { |entity| entity&.project.try(:id) }
|
||||
expose :title, :description
|
||||
expose :state, :created_at, :updated_at
|
||||
|
||||
# Avoids an N+1 query when metadata is included
|
||||
def issuable_metadata(subject, options, method, args = nil)
|
||||
cached_subject = options.dig(:issuable_metadata, subject.id)
|
||||
(cached_subject || subject).public_send(method, *args) # rubocop: disable GitlabSecurity/PublicSend
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
lib/api/entities/issuable_references.rb
Normal file
19
lib/api/entities/issuable_references.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module API
|
||||
module Entities
|
||||
class IssuableReferences < Grape::Entity
|
||||
expose :short do |issuable|
|
||||
issuable.to_reference
|
||||
end
|
||||
|
||||
expose :relative do |issuable, options|
|
||||
issuable.to_reference(options[:group] || options[:project])
|
||||
end
|
||||
|
||||
expose :full do |issuable|
|
||||
issuable.to_reference(full: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
12
lib/api/entities/protected_branch.rb
Normal file
12
lib/api/entities/protected_branch.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module API
|
||||
module Entities
|
||||
class ProtectedBranch < Grape::Entity
|
||||
expose :id
|
||||
expose :name
|
||||
expose :push_access_levels, using: Entities::ProtectedRefAccess
|
||||
expose :merge_access_levels, using: Entities::ProtectedRefAccess
|
||||
end
|
||||
end
|
||||
end
|
12
lib/api/entities/protected_ref_access.rb
Normal file
12
lib/api/entities/protected_ref_access.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module API
|
||||
module Entities
|
||||
class ProtectedRefAccess < Grape::Entity
|
||||
expose :access_level
|
||||
expose :access_level_description do |protected_ref_access|
|
||||
protected_ref_access.humanize
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
10
lib/api/entities/protected_tag.rb
Normal file
10
lib/api/entities/protected_tag.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module API
|
||||
module Entities
|
||||
class ProtectedTag < Grape::Entity
|
||||
expose :name
|
||||
expose :create_access_levels, using: Entities::ProtectedRefAccess
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue