diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /lib/api/entities | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) | |
download | gitlab-ce-a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4.tar.gz |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'lib/api/entities')
-rw-r--r-- | lib/api/entities/basic_project_details.rb | 31 | ||||
-rw-r--r-- | lib/api/entities/commit.rb | 1 | ||||
-rw-r--r-- | lib/api/entities/group_detail.rb | 6 | ||||
-rw-r--r-- | lib/api/entities/issue_basic.rb | 2 | ||||
-rw-r--r-- | lib/api/entities/label_basic.rb | 2 | ||||
-rw-r--r-- | lib/api/entities/merge_request_basic.rb | 6 | ||||
-rw-r--r-- | lib/api/entities/package.rb | 8 | ||||
-rw-r--r-- | lib/api/entities/packages/debian/distribution.rb | 23 | ||||
-rw-r--r-- | lib/api/entities/project.rb | 19 | ||||
-rw-r--r-- | lib/api/entities/project_repository_storage.rb | 16 | ||||
-rw-r--r-- | lib/api/entities/runner.rb | 1 | ||||
-rw-r--r-- | lib/api/entities/snippet.rb | 10 | ||||
-rw-r--r-- | lib/api/entities/user_preferences.rb | 2 |
13 files changed, 99 insertions, 28 deletions
diff --git a/lib/api/entities/basic_project_details.rb b/lib/api/entities/basic_project_details.rb index 2de49d6ed40..c75b74b4368 100644 --- a/lib/api/entities/basic_project_details.rb +++ b/lib/api/entities/basic_project_details.rb @@ -4,15 +4,13 @@ module API module Entities class BasicProjectDetails < Entities::ProjectIdentity include ::API::ProjectsRelationBuilder + include Gitlab::Utils::StrongMemoize 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| - # Tags is a preloaded association. If we perform then sorting - # through the database, it will trigger a new query, ending up - # in an N+1 if we have several projects - project.tags.pluck(:name).sort # rubocop:disable CodeReuse/ActiveRecord - end + + expose :topic_names, as: :tag_list + expose :topic_names, as: :topics expose :ssh_url_to_repo, :http_url_to_repo, :web_url, :readme_url @@ -40,16 +38,29 @@ module API # 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)` + # Preloading topics, should be done with using only `:topics`, + # as `:topics` are defined as: `has_many :topics, through: :taggings` + # N+1 is solved then by using `subject.topics.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(:import_state, :topics) .preload(:auto_devops) .preload(namespace: [:route, :owner]) end # rubocop: enable CodeReuse/ActiveRecord + + private + + alias_method :project, :object + + def topic_names + # Topics is a preloaded association. If we perform then sorting + # through the database, it will trigger a new query, ending up + # in an N+1 if we have several projects + strong_memoize(:topic_names) do + project.topics.pluck(:name).sort # rubocop:disable CodeReuse/ActiveRecord + end + end end end end diff --git a/lib/api/entities/commit.rb b/lib/api/entities/commit.rb index 3eaf896f1ac..fd23c23b980 100644 --- a/lib/api/entities/commit.rb +++ b/lib/api/entities/commit.rb @@ -9,6 +9,7 @@ module API expose :safe_message, as: :message expose :author_name, :author_email, :authored_date expose :committer_name, :committer_email, :committed_date + expose :trailers expose :web_url do |commit, _options| Gitlab::UrlBuilder.build(commit) diff --git a/lib/api/entities/group_detail.rb b/lib/api/entities/group_detail.rb index e63a3fc1334..408254a89be 100644 --- a/lib/api/entities/group_detail.rb +++ b/lib/api/entities/group_detail.rb @@ -29,11 +29,7 @@ module API end def projects_limit - if ::Feature.enabled?(:limit_projects_in_groups_api, default_enabled: true) - GroupProjectsFinder::DEFAULT_PROJECTS_LIMIT - else - nil - end + GroupProjectsFinder::DEFAULT_PROJECTS_LIMIT end end end diff --git a/lib/api/entities/issue_basic.rb b/lib/api/entities/issue_basic.rb index d27cc5498bd..6c332870228 100644 --- a/lib/api/entities/issue_basic.rb +++ b/lib/api/entities/issue_basic.rb @@ -23,7 +23,7 @@ module API expose :issue_type, as: :type, format_with: :upcase, - documentation: { type: "String", desc: "One of #{Issue.issue_types.keys.map(&:upcase)}" } + documentation: { type: "String", desc: "One of #{::Issue.issue_types.keys.map(&:upcase)}" } expose :assignee, using: ::API::Entities::UserBasic do |issue| issue.assignees.first diff --git a/lib/api/entities/label_basic.rb b/lib/api/entities/label_basic.rb index 00ecea26ec3..ed52688638e 100644 --- a/lib/api/entities/label_basic.rb +++ b/lib/api/entities/label_basic.rb @@ -3,7 +3,7 @@ module API module Entities class LabelBasic < Grape::Entity - expose :id, :name, :color, :description, :description_html, :text_color, :remove_on_close + expose :id, :name, :color, :description, :description_html, :text_color end end end diff --git a/lib/api/entities/merge_request_basic.rb b/lib/api/entities/merge_request_basic.rb index cf8d03bf176..d5cf2f653db 100644 --- a/lib/api/entities/merge_request_basic.rb +++ b/lib/api/entities/merge_request_basic.rb @@ -36,7 +36,11 @@ module API merge_request.labels.map(&:title).sort end end - expose :work_in_progress?, as: :work_in_progress + expose :draft?, as: :draft + + # [Deprecated] see draft + # + expose :draft?, as: :work_in_progress expose :milestone, using: Entities::Milestone expose :merge_when_pipeline_succeeds diff --git a/lib/api/entities/package.rb b/lib/api/entities/package.rb index 2f60a0bf6bd..1efd457aa5f 100644 --- a/lib/api/entities/package.rb +++ b/lib/api/entities/package.rb @@ -25,8 +25,12 @@ module API expose :status expose :_links do - expose :web_path do |package| - ::Gitlab::Routing.url_helpers.project_package_path(package.project, package) + expose :web_path do |package, opts| + if package.infrastructure_package? + ::Gitlab::Routing.url_helpers.namespace_project_infrastructure_registry_path(opts[:namespace], package.project, package) + else + ::Gitlab::Routing.url_helpers.project_package_path(package.project, package) + end end expose :delete_api_path, if: can_destroy(:package, &:project) do |package| diff --git a/lib/api/entities/packages/debian/distribution.rb b/lib/api/entities/packages/debian/distribution.rb new file mode 100644 index 00000000000..97a3c479f40 --- /dev/null +++ b/lib/api/entities/packages/debian/distribution.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module API + module Entities + module Packages + module Debian + class Distribution < Grape::Entity + expose :id + expose :codename + expose :suite + expose :origin + expose :label + expose :version + expose :description + expose :valid_time_duration_seconds + + expose :component_names, as: :components + expose :architecture_names, as: :architectures + end + end + end + end +end diff --git a/lib/api/entities/project.rb b/lib/api/entities/project.rb index 442013c07dd..68d91fc6970 100644 --- a/lib/api/entities/project.rb +++ b/lib/api/entities/project.rb @@ -43,7 +43,6 @@ module API expose :visibility expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group } expose :resolve_outdated_diff_discussions - expose :container_registry_enabled expose :container_expiration_policy, using: Entities::ContainerExpirationPolicy, if: -> (project, _) { project.container_expiration_policy } @@ -54,6 +53,13 @@ module API expose(:wiki_enabled) { |project, options| project.feature_available?(:wiki, options[:current_user]) } expose(:jobs_enabled) { |project, options| project.feature_available?(:builds, options[:current_user]) } expose(:snippets_enabled) { |project, options| project.feature_available?(:snippets, options[:current_user]) } + expose(:container_registry_enabled) do |project, options| + if ::Feature.enabled?(:read_container_registry_access_level, project.namespace, default_enabled: :yaml) + project.feature_available?(:container_registry, options[:current_user]) + else + project.read_attribute(:container_registry_enabled) + end + end expose :service_desk_enabled expose :service_desk_address @@ -89,6 +95,7 @@ module API expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] } expose :ci_default_git_depth expose :ci_forward_deployment_enabled + expose :ci_job_token_scope_enabled expose :public_builds, as: :public_jobs expose :build_git_strategy, if: lambda { |project, options| options[:user_can_admin_project] } do |project, options| project.build_allow_git_fetch ? 'fetch' : 'clone' @@ -108,6 +115,7 @@ module API expose :remove_source_branch_after_merge expose :printing_merge_request_link_enabled expose :merge_method + expose :squash_option expose :suggestion_commit_message expose :statistics, using: 'API::Entities::ProjectStatistics', if: -> (project, options) { options[:statistics] && Ability.allowed?(options[:current_user], :read_statistics, project) @@ -120,12 +128,13 @@ module API expose :repository_storage, if: ->(project, options) { Ability.allowed?(options[:current_user], :change_repository_storage, project) } + expose :keep_latest_artifacts_available?, as: :keep_latest_artifact # 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)` + # Preloading topics, should be done with using only `:topics`, + # as `:topics` are defined as: `has_many :topics, through: :taggings` + # N+1 is solved then by using `subject.topics.map(&:name)` # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555 super(projects_relation).preload(group: :namespace_settings) .preload(:ci_cd_settings) @@ -136,7 +145,7 @@ module API .preload(project_group_links: { group: :route }, fork_network: :root_project, fork_network_member: :forked_from_project, - forked_from_project: [:route, :forks, :tags, :group, :project_feature, namespace: [:route, :owner]]) + forked_from_project: [:route, :topics, :group, :project_feature, namespace: [:route, :owner]]) end # rubocop: enable CodeReuse/ActiveRecord diff --git a/lib/api/entities/project_repository_storage.rb b/lib/api/entities/project_repository_storage.rb new file mode 100644 index 00000000000..0816bebde2c --- /dev/null +++ b/lib/api/entities/project_repository_storage.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module API + module Entities + class ProjectRepositoryStorage < Grape::Entity + include Gitlab::Routing + + expose :disk_path do |project| + project.repository.disk_path + end + + expose :id, as: :project_id + expose :repository_storage, :created_at + end + end +end diff --git a/lib/api/entities/runner.rb b/lib/api/entities/runner.rb index 6165b54cddb..e78f14cf920 100644 --- a/lib/api/entities/runner.rb +++ b/lib/api/entities/runner.rb @@ -8,6 +8,7 @@ module API expose :ip_address expose :active expose :instance_type?, as: :is_shared + expose :runner_type expose :name expose :online?, as: :online expose :status diff --git a/lib/api/entities/snippet.rb b/lib/api/entities/snippet.rb index f05e593a302..af885aaf0eb 100644 --- a/lib/api/entities/snippet.rb +++ b/lib/api/entities/snippet.rb @@ -5,16 +5,22 @@ module API class Snippet < BasicSnippet expose :author, using: Entities::UserBasic expose :file_name do |snippet| - snippet.file_name_on_repo || snippet.file_name + snippet_files.first || snippet.file_name end expose :files do |snippet, options| - snippet.list_files.map do |file| + snippet_files.map do |file| { path: file, raw_url: Gitlab::UrlBuilder.build(snippet, file: file, ref: snippet.repository.root_ref) } end end + + private + + def snippet_files + @snippet_files ||= object.list_files + end end end end diff --git a/lib/api/entities/user_preferences.rb b/lib/api/entities/user_preferences.rb index 7a6df9b6c59..ceee6c610d3 100644 --- a/lib/api/entities/user_preferences.rb +++ b/lib/api/entities/user_preferences.rb @@ -3,7 +3,7 @@ module API module Entities class UserPreferences < Grape::Entity - expose :id, :user_id, :view_diffs_file_by_file + expose :id, :user_id, :view_diffs_file_by_file, :show_whitespace_in_diffs end end end |