Commit 20c9d7f3 authored by Stan Hu's avatar Stan Hu

Merge branch 'refactoring-entities-file-7' into 'master'

Separate commit entities into own classes

See merge request gitlab-org/gitlab!24085
parents 83cf1e08 9f5aabaa
---
title: Separate commit entities into own class files
merge_request: 24085
author: Rajendra Kadam
type: added
...@@ -128,51 +128,6 @@ module API ...@@ -128,51 +128,6 @@ module API
end end
end end
class DiffRefs < Grape::Entity
expose :base_sha, :head_sha, :start_sha
end
class Commit < Grape::Entity
expose :id, :short_id, :created_at
expose :parent_ids
expose :full_title, as: :title
expose :safe_message, as: :message
expose :author_name, :author_email, :authored_date
expose :committer_name, :committer_email, :committed_date
end
class CommitStats < Grape::Entity
expose :additions, :deletions, :total
end
class CommitWithStats < Commit
expose :stats, using: Entities::CommitStats
end
class CommitDetail < Commit
expose :stats, using: Entities::CommitStats, if: :stats
expose :status
expose :project_id
expose :last_pipeline do |commit, options|
pipeline = commit.last_pipeline if can_read_pipeline?
::API::Entities::PipelineBasic.represent(pipeline, options)
end
private
def can_read_pipeline?
Ability.allowed?(options[:current_user], :read_pipeline, object.last_pipeline)
end
end
class CommitSignature < Grape::Entity
expose :gpg_key_id
expose :gpg_key_primary_keyid, :gpg_key_user_name, :gpg_key_user_email
expose :verification_status
expose :gpg_key_subkey_id
end
class BasicRef < Grape::Entity class BasicRef < Grape::Entity
expose :type, :name expose :type, :name
end end
......
# frozen_string_literal: true
module API
module Entities
class Commit < Grape::Entity
expose :id, :short_id, :created_at
expose :parent_ids
expose :full_title, as: :title
expose :safe_message, as: :message
expose :author_name, :author_email, :authored_date
expose :committer_name, :committer_email, :committed_date
end
end
end
# frozen_string_literal: true
module API
module Entities
class CommitDetail < Commit
expose :stats, using: Entities::CommitStats, if: :stats
expose :status
expose :project_id
expose :last_pipeline do |commit, options|
pipeline = commit.last_pipeline if can_read_pipeline?
::API::Entities::PipelineBasic.represent(pipeline, options)
end
private
def can_read_pipeline?
Ability.allowed?(options[:current_user], :read_pipeline, object.last_pipeline)
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class CommitSignature < Grape::Entity
expose :gpg_key_id
expose :gpg_key_primary_keyid, :gpg_key_user_name, :gpg_key_user_email
expose :verification_status
expose :gpg_key_subkey_id
end
end
end
# frozen_string_literal: true
module API
module Entities
class CommitStats < Grape::Entity
expose :additions, :deletions, :total
end
end
end
# frozen_string_literal: true
module API
module Entities
class CommitWithStats < Commit
expose :stats, using: Entities::CommitStats
end
end
end
# frozen_string_literal: true
module API
module Entities
class DiffRefs < Grape::Entity
expose :base_sha, :head_sha, :start_sha
end
end
end
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