diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-02 03:08:37 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-02 03:08:37 +0000 |
commit | 78214bf7421d73e288466100df584d99e91154af (patch) | |
tree | 370acdddcf33f6df889841f1a9b762190466cf9d /lib/api | |
parent | d0356412dfc91d02585f0a177c65677dbe2944a3 (diff) | |
download | gitlab-ce-78214bf7421d73e288466100df584d99e91154af.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 54 | ||||
-rw-r--r-- | lib/api/entities/diff.rb | 13 | ||||
-rw-r--r-- | lib/api/entities/issuable_entity.rb | 18 | ||||
-rw-r--r-- | lib/api/entities/issuable_references.rb | 19 | ||||
-rw-r--r-- | lib/api/entities/protected_branch.rb | 12 | ||||
-rw-r--r-- | lib/api/entities/protected_ref_access.rb | 12 | ||||
-rw-r--r-- | lib/api/entities/protected_tag.rb | 10 |
7 files changed, 84 insertions, 54 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 88ca0906283..bd7b2fd9433 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -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 } diff --git a/lib/api/entities/diff.rb b/lib/api/entities/diff.rb new file mode 100644 index 00000000000..e92bc5d6b68 --- /dev/null +++ b/lib/api/entities/diff.rb @@ -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 diff --git a/lib/api/entities/issuable_entity.rb b/lib/api/entities/issuable_entity.rb new file mode 100644 index 00000000000..5bee59de539 --- /dev/null +++ b/lib/api/entities/issuable_entity.rb @@ -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 diff --git a/lib/api/entities/issuable_references.rb b/lib/api/entities/issuable_references.rb new file mode 100644 index 00000000000..1bf078847cf --- /dev/null +++ b/lib/api/entities/issuable_references.rb @@ -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 diff --git a/lib/api/entities/protected_branch.rb b/lib/api/entities/protected_branch.rb new file mode 100644 index 00000000000..e41d497c836 --- /dev/null +++ b/lib/api/entities/protected_branch.rb @@ -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 diff --git a/lib/api/entities/protected_ref_access.rb b/lib/api/entities/protected_ref_access.rb new file mode 100644 index 00000000000..ab878be45d2 --- /dev/null +++ b/lib/api/entities/protected_ref_access.rb @@ -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 diff --git a/lib/api/entities/protected_tag.rb b/lib/api/entities/protected_tag.rb new file mode 100644 index 00000000000..dc397f01af6 --- /dev/null +++ b/lib/api/entities/protected_tag.rb @@ -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 |