Commit 40144ebf authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Peter Leitzen

Separate code review, design, group module into own module files

parent 8f75140b
---
title: Separate code review, design and group modules into own class files
merge_request: 27860
author: Rajendra Kadam
type: added
...@@ -3,37 +3,9 @@ ...@@ -3,37 +3,9 @@
module EE module EE
module API module API
module Entities module Entities
module ProtectedBranch
extend ActiveSupport::Concern
prepended do
expose :unprotect_access_levels, using: ::API::Entities::ProtectedRefAccess
expose :code_owner_approval_required
end
end
module IssueBasic
extend ActiveSupport::Concern
prepended do
expose :weight, if: ->(issue, _) { issue.supports_weight? }
end
end
######################## ########################
# EE-specific entities # # EE-specific entities #
######################## ########################
module DesignManagement
class Design < Grape::Entity
expose :id
expose :project_id
expose :filename
expose :image_url do |design|
::Gitlab::UrlBuilder.build(design)
end
end
end
module Nuget module Nuget
class ServiceIndex < Grape::Entity class ServiceIndex < Grape::Entity
expose :version expose :version
...@@ -96,56 +68,6 @@ module EE ...@@ -96,56 +68,6 @@ module EE
expose :data, using: EE::API::Entities::Nuget::SearchResult expose :data, using: EE::API::Entities::Nuget::SearchResult
end end
end end
module Analytics
module CodeReview
class MergeRequest < ::API::Entities::MergeRequestSimple
expose :milestone, using: ::API::Entities::Milestone
expose :author, using: ::API::Entities::UserBasic
expose :approved_by_users, as: :approved_by, using: ::API::Entities::UserBasic
expose :notes_count do |mr|
if options[:issuable_metadata]
# Avoids an N+1 query when metadata is included
options[:issuable_metadata][mr.id].user_notes_count
else
mr.notes.user.count
end
end
expose :review_time do |mr|
time = mr.metrics.review_time
next unless time
(time / ActiveSupport::Duration::SECONDS_PER_HOUR).floor
end
expose :diff_stats
private
# rubocop: disable CodeReuse/ActiveRecord
def diff_stats
result = {
additions: object.diffs.diff_files.sum(&:added_lines),
deletions: object.diffs.diff_files.sum(&:removed_lines),
commits_count: object.commits_count
}
result[:total] = result[:additions] + result[:deletions]
result
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
module GroupActivity
class IssuesCount < Grape::Entity
expose :issues_count
end
class MergeRequestsCount < Grape::Entity
expose :merge_requests_count
end
end
end
end end
end end
end end
# frozen_string_literal: true
module EE
module API
module Entities
module Analytics
module CodeReview
class MergeRequest < ::API::Entities::MergeRequestSimple
expose :milestone, using: ::API::Entities::Milestone
expose :author, using: ::API::Entities::UserBasic
expose :approved_by_users, as: :approved_by, using: ::API::Entities::UserBasic
expose :notes_count do |mr|
if options[:issuable_metadata]
# Avoids an N+1 query when metadata is included
options[:issuable_metadata][mr.id].user_notes_count
else
mr.notes.user.count
end
end
expose :review_time do |mr|
time = mr.metrics.review_time
next unless time
(time / ActiveSupport::Duration::SECONDS_PER_HOUR).floor
end
expose :diff_stats
private
# rubocop: disable CodeReuse/ActiveRecord
def diff_stats
result = {
additions: object.diffs.diff_files.sum(&:added_lines),
deletions: object.diffs.diff_files.sum(&:removed_lines),
commits_count: object.commits_count
}
result[:total] = result[:additions] + result[:deletions]
result
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Analytics
module GroupActivity
class IssuesCount < Grape::Entity
expose :issues_count
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module Analytics
module GroupActivity
class MergeRequestsCount < Grape::Entity
expose :merge_requests_count
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module DesignManagement
class Design < Grape::Entity
expose :id
expose :project_id
expose :filename
expose :image_url do |design|
::Gitlab::UrlBuilder.build(design)
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module IssueBasic
extend ActiveSupport::Concern
prepended do
expose :weight, if: ->(issue, _) { issue.supports_weight? }
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
module ProtectedBranch
extend ActiveSupport::Concern
prepended do
expose :unprotect_access_levels, using: ::API::Entities::ProtectedRefAccess
expose :code_owner_approval_required
end
end
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