summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb95
-rw-r--r--lib/api/entities/basic_project_details.rb55
-rw-r--r--lib/api/entities/container_expiration_policy.rb14
-rw-r--r--lib/api/entities/project_import_status.rb14
-rw-r--r--lib/api/entities/project_statistics.rb14
-rw-r--r--lib/api/entities/remote_mirror.rb17
-rw-r--r--lib/api/merge_requests.rb8
-rw-r--r--lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb5
-rw-r--r--lib/gitlab/background_migration/user_mentions/models/concerns/isolated_mentionable.rb (renamed from lib/gitlab/background_migration/user_mentions/models/isolated_mentionable.rb)0
-rw-r--r--lib/gitlab/background_migration/user_mentions/models/concerns/mentionable_migration_methods.rb24
-rw-r--r--lib/gitlab/background_migration/user_mentions/models/epic.rb1
-rw-r--r--lib/gitlab/database/subquery.rb16
-rw-r--r--lib/gitlab/jira/http_client.rb2
13 files changed, 146 insertions, 119 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 32a5f3ce33d..07ed6bd7e0b 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -2,86 +2,6 @@
module API
module Entities
- class RemoteMirror < Grape::Entity
- expose :id
- expose :enabled
- expose :safe_url, as: :url
- expose :update_status
- expose :last_update_at
- expose :last_update_started_at
- expose :last_successful_update_at
- expose :last_error
- expose :only_protected_branches
- end
-
- class ContainerExpirationPolicy < Grape::Entity
- expose :cadence
- expose :enabled
- expose :keep_n
- expose :older_than
- expose :name_regex
- expose :next_run_at
- end
-
- class ProjectImportStatus < ProjectIdentity
- expose :import_status
-
- # TODO: Use `expose_nil` once we upgrade the grape-entity gem
- expose :import_error, if: lambda { |project, _ops| project.import_state&.last_error } do |project|
- project.import_state.last_error
- end
- end
-
- class BasicProjectDetails < ProjectIdentity
- include ::API::ProjectsRelationBuilder
-
- expose :default_branch, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) }
- # Avoids an N+1 query: https://github.com/mbleigh/acts-as-taggable-on/issues/91#issuecomment-168273770
- expose :tag_list do |project|
- # project.tags.order(:name).pluck(:name) is the most suitable option
- # to avoid loading all the ActiveRecord objects but, if we use it here
- # it override the preloaded associations and makes a query
- # (fixed in https://github.com/rails/rails/pull/25976).
- project.tags.map(&:name).sort
- end
-
- expose :ssh_url_to_repo, :http_url_to_repo, :web_url, :readme_url
-
- expose :license_url, if: :license do |project|
- license = project.repository.license_blob
-
- if license
- Gitlab::Routing.url_helpers.project_blob_url(project, File.join(project.default_branch, license.path))
- end
- end
-
- expose :license, with: 'API::Entities::LicenseBasic', if: :license do |project|
- project.repository.license
- end
-
- expose :avatar_url do |project, options|
- project.avatar_url(only_path: false)
- end
-
- expose :star_count, :forks_count
- expose :last_activity_at
- expose :namespace, using: 'API::Entities::NamespaceBasic'
- expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
-
- # rubocop: disable CodeReuse/ActiveRecord
- def self.preload_relation(projects_relation, options = {})
- # Preloading tags, should be done with using only `:tags`,
- # as `:tags` are defined as: `has_many :tags, through: :taggings`
- # N+1 is solved then by using `subject.tags.map(&:name)`
- # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555
- projects_relation.preload(:project_feature, :route)
- .preload(:import_state, :tags)
- .preload(:auto_devops)
- .preload(namespace: [:route, :owner])
- end
- # rubocop: enable CodeReuse/ActiveRecord
- end
-
class Project < BasicProjectDetails
include ::API::Helpers::RelatedResourcesHelpers
@@ -208,15 +128,6 @@ module API
end
end
- class ProjectStatistics < Grape::Entity
- expose :commit_count
- expose :storage_size
- expose :repository_size
- expose :wiki_size
- expose :lfs_objects_size
- expose :build_artifacts_size, as: :job_artifacts_size
- end
-
class ProjectDailyFetches < Grape::Entity
expose :fetch_count, as: :count
expose :date
@@ -759,12 +670,6 @@ module API
end
end
- class MergeRequestContextCommit < Grape::Entity
- expose :sha, :relative_order, :new_file, :renamed_file,
- :deleted_file, :too_large, :a_mode, :b_mode, :new_path, :old_path,
- :diff, :binary
- end
-
class SSHKey < Grape::Entity
expose :id, :title, :key, :created_at
end
diff --git a/lib/api/entities/basic_project_details.rb b/lib/api/entities/basic_project_details.rb
new file mode 100644
index 00000000000..9ea3aeb9903
--- /dev/null
+++ b/lib/api/entities/basic_project_details.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class BasicProjectDetails < ProjectIdentity
+ include ::API::ProjectsRelationBuilder
+
+ expose :default_branch, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) }
+ # Avoids an N+1 query: https://github.com/mbleigh/acts-as-taggable-on/issues/91#issuecomment-168273770
+ expose :tag_list do |project|
+ # project.tags.order(:name).pluck(:name) is the most suitable option
+ # to avoid loading all the ActiveRecord objects but, if we use it here
+ # it override the preloaded associations and makes a query
+ # (fixed in https://github.com/rails/rails/pull/25976).
+ project.tags.map(&:name).sort
+ end
+
+ expose :ssh_url_to_repo, :http_url_to_repo, :web_url, :readme_url
+
+ expose :license_url, if: :license do |project|
+ license = project.repository.license_blob
+
+ if license
+ Gitlab::Routing.url_helpers.project_blob_url(project, File.join(project.default_branch, license.path))
+ end
+ end
+
+ expose :license, with: 'API::Entities::LicenseBasic', if: :license do |project|
+ project.repository.license
+ end
+
+ expose :avatar_url do |project, options|
+ project.avatar_url(only_path: false)
+ end
+
+ expose :star_count, :forks_count
+ expose :last_activity_at
+ expose :namespace, using: 'API::Entities::NamespaceBasic'
+ expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ def self.preload_relation(projects_relation, options = {})
+ # Preloading tags, should be done with using only `:tags`,
+ # as `:tags` are defined as: `has_many :tags, through: :taggings`
+ # N+1 is solved then by using `subject.tags.map(&:name)`
+ # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555
+ projects_relation.preload(:project_feature, :route)
+ .preload(:import_state, :tags)
+ .preload(:auto_devops)
+ .preload(namespace: [:route, :owner])
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+ end
+ end
+end
diff --git a/lib/api/entities/container_expiration_policy.rb b/lib/api/entities/container_expiration_policy.rb
new file mode 100644
index 00000000000..853bbb9b76b
--- /dev/null
+++ b/lib/api/entities/container_expiration_policy.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class ContainerExpirationPolicy < Grape::Entity
+ expose :cadence
+ expose :enabled
+ expose :keep_n
+ expose :older_than
+ expose :name_regex
+ expose :next_run_at
+ end
+ end
+end
diff --git a/lib/api/entities/project_import_status.rb b/lib/api/entities/project_import_status.rb
new file mode 100644
index 00000000000..0b884b43e9e
--- /dev/null
+++ b/lib/api/entities/project_import_status.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class ProjectImportStatus < ProjectIdentity
+ expose :import_status
+
+ # TODO: Use `expose_nil` once we upgrade the grape-entity gem
+ expose :import_error, if: lambda { |project, _ops| project.import_state&.last_error } do |project|
+ project.import_state.last_error
+ end
+ end
+ end
+end
diff --git a/lib/api/entities/project_statistics.rb b/lib/api/entities/project_statistics.rb
new file mode 100644
index 00000000000..e5f6165da31
--- /dev/null
+++ b/lib/api/entities/project_statistics.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class ProjectStatistics < Grape::Entity
+ expose :commit_count
+ expose :storage_size
+ expose :repository_size
+ expose :wiki_size
+ expose :lfs_objects_size
+ expose :build_artifacts_size, as: :job_artifacts_size
+ end
+ end
+end
diff --git a/lib/api/entities/remote_mirror.rb b/lib/api/entities/remote_mirror.rb
new file mode 100644
index 00000000000..dde3e9dea99
--- /dev/null
+++ b/lib/api/entities/remote_mirror.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class RemoteMirror < Grape::Entity
+ expose :id
+ expose :enabled
+ expose :safe_url, as: :url
+ expose :update_status
+ expose :last_update_at
+ expose :last_update_started_at
+ expose :last_successful_update_at
+ expose :last_error
+ expose :only_protected_branches
+ end
+ end
+end
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 6397a376af7..c4ab84c5200 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -293,7 +293,7 @@ module API
end
desc 'Get the context commits of a merge request' do
- success Entities::CommitEntity
+ success Entities::Commit
end
get ':id/merge_requests/:merge_request_iid/context_commits' do
merge_request = find_merge_request_with_access(params[:merge_request_iid])
@@ -301,8 +301,10 @@ module API
not_found! unless project.context_commits_enabled?
- context_commits = merge_request.context_commits
- CommitEntity.represent(context_commits, type: :full, request: merge_request)
+ context_commits =
+ paginate(merge_request.merge_request_context_commits).map(&:to_commit)
+
+ present context_commits, with: Entities::Commit
end
params do
diff --git a/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb b/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb
index e951b44b036..7d40dfbcdc4 100644
--- a/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb
+++ b/lib/gitlab/background_migration/user_mentions/create_resource_user_mention.rb
@@ -24,14 +24,11 @@ module Gitlab
mentions << record.build_mention_values
end
- no_quote_columns = [:note_id]
- no_quote_columns << resource_user_mention_model.resource_foreign_key
-
Gitlab::Database.bulk_insert(
resource_user_mention_model.table_name,
mentions,
return_ids: true,
- disable_quote: no_quote_columns,
+ disable_quote: resource_model.no_quote_columns,
on_conflict: :do_nothing
)
end
diff --git a/lib/gitlab/background_migration/user_mentions/models/isolated_mentionable.rb b/lib/gitlab/background_migration/user_mentions/models/concerns/isolated_mentionable.rb
index 40aab896212..40aab896212 100644
--- a/lib/gitlab/background_migration/user_mentions/models/isolated_mentionable.rb
+++ b/lib/gitlab/background_migration/user_mentions/models/concerns/isolated_mentionable.rb
diff --git a/lib/gitlab/background_migration/user_mentions/models/concerns/mentionable_migration_methods.rb b/lib/gitlab/background_migration/user_mentions/models/concerns/mentionable_migration_methods.rb
new file mode 100644
index 00000000000..fa479cb0ed3
--- /dev/null
+++ b/lib/gitlab/background_migration/user_mentions/models/concerns/mentionable_migration_methods.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ module UserMentions
+ module Models
+ # Extract common no_quote_columns method used in determining the columns that do not need
+ # to be quoted for corresponding models
+ module MentionableMigrationMethods
+ extend ::ActiveSupport::Concern
+
+ class_methods do
+ def no_quote_columns
+ [
+ :note_id,
+ user_mention_model.resource_foreign_key
+ ]
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/background_migration/user_mentions/models/epic.rb b/lib/gitlab/background_migration/user_mentions/models/epic.rb
index 019d8f0ea8b..9797c86478e 100644
--- a/lib/gitlab/background_migration/user_mentions/models/epic.rb
+++ b/lib/gitlab/background_migration/user_mentions/models/epic.rb
@@ -8,6 +8,7 @@ module Gitlab
class Epic < ActiveRecord::Base
include IsolatedMentionable
include CacheMarkdownField
+ include MentionableMigrationMethods
attr_mentionable :title, pipeline: :single_line
attr_mentionable :description
diff --git a/lib/gitlab/database/subquery.rb b/lib/gitlab/database/subquery.rb
deleted file mode 100644
index 2a6f39c6a27..00000000000
--- a/lib/gitlab/database/subquery.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module Database
- module Subquery
- class << self
- def self_join(relation)
- t = relation.arel_table
- t2 = relation.arel.as('t2')
-
- relation.unscoped.joins(t.join(t2).on(t[:id].eq(t2[:id])).join_sources.first)
- end
- end
- end
- end
-end
diff --git a/lib/gitlab/jira/http_client.rb b/lib/gitlab/jira/http_client.rb
index 0c8b509740c..c09d8170d17 100644
--- a/lib/gitlab/jira/http_client.rb
+++ b/lib/gitlab/jira/http_client.rb
@@ -12,7 +12,7 @@ module Gitlab
def request(*args)
result = make_request(*args)
- raise JIRA::HTTPError.new(result) unless result.response.is_a?(Net::HTTPSuccess)
+ raise JIRA::HTTPError.new(result.response) unless result.response.is_a?(Net::HTTPSuccess)
result
end