diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /app/serializers | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'app/serializers')
23 files changed, 103 insertions, 99 deletions
diff --git a/app/serializers/ci/pipeline_entity.rb b/app/serializers/ci/pipeline_entity.rb index 20aeb978520..143017c5159 100644 --- a/app/serializers/ci/pipeline_entity.rb +++ b/app/serializers/ci/pipeline_entity.rb @@ -4,12 +4,13 @@ class Ci::PipelineEntity < Grape::Entity include RequestAwareEntity include Gitlab::Utils::StrongMemoize - delegate :name, :failure_reason, :coverage, to: :presented_pipeline + delegate :event_type_name, :failure_reason, :coverage, to: :presented_pipeline expose :id expose :iid expose :user, using: UserEntity expose :active?, as: :active + expose :name, if: -> (pipeline, _) { Feature.enabled?(:pipeline_name, pipeline.project) } # Coverage isn't always necessary (e.g. when displaying project pipelines in # the UI). Instead of creating an entirely different entity we just allow the @@ -40,7 +41,8 @@ class Ci::PipelineEntity < Grape::Entity expose :stages, using: StageEntity expose :duration expose :finished_at - expose :name + expose :event_type_name + expose :event_type_name, as: :name # To be removed in 15.7 end expose :merge_request, if: -> (*) { has_presentable_merge_request? }, with: MergeRequestForPipelineEntity do |pipeline| diff --git a/app/serializers/codequality_degradation_entity.rb b/app/serializers/codequality_degradation_entity.rb index 6289260465b..52945a753dc 100644 --- a/app/serializers/codequality_degradation_entity.rb +++ b/app/serializers/codequality_degradation_entity.rb @@ -13,4 +13,6 @@ class CodequalityDegradationEntity < Grape::Entity expose :line do |degradation| degradation.dig(:location, :lines, :begin) || degradation.dig(:location, :positions, :begin, :line) end + + expose :web_url end diff --git a/app/serializers/detailed_status_entity.rb b/app/serializers/detailed_status_entity.rb index 4f23ef0ed82..ed8ac9f40f7 100644 --- a/app/serializers/detailed_status_entity.rb +++ b/app/serializers/detailed_status_entity.rb @@ -3,12 +3,25 @@ class DetailedStatusEntity < Grape::Entity include RequestAwareEntity - expose :icon, :text, :label, :group - expose :status_tooltip, as: :tooltip - expose :has_details?, as: :has_details - expose :details_path + expose :icon, documentation: { type: 'string', example: 'status_success' } + expose :text, documentation: { type: 'string', example: 'passed' } + expose :label, documentation: { type: 'string', example: 'passed' } + expose :group, documentation: { type: 'string', example: 'success' } + expose :status_tooltip, as: :tooltip, documentation: { type: 'string', example: 'passed' } + expose :has_details?, as: :has_details, documentation: { type: 'boolean', example: true } + expose :details_path, documentation: { type: 'string', example: '/test-group/test-project/-/pipelines/287' } - expose :illustration do |status| + expose :illustration, documentation: { + type: 'object', + example: <<~JSON + { + "image": "illustrations/job_not_triggered.svg", + "size": "svg-306", + "title": "This job has not been triggered yet", + "content": "This job depends on upstream jobs that need to succeed in order for this job to be triggered" + } + JSON + } do |status| illustration = { image: ActionController::Base.helpers.image_path(status.illustration[:image]) } @@ -19,15 +32,17 @@ class DetailedStatusEntity < Grape::Entity # ignored end - expose :favicon do |status| + expose :favicon, + documentation: { type: 'string', + example: '/assets/ci_favicons/favicon_status_success.png' } do |status| Gitlab::Favicon.status_overlay(status.favicon) end expose :action, if: -> (status, _) { status.has_action? } do - expose :action_icon, as: :icon - expose :action_title, as: :title - expose :action_path, as: :path - expose :action_method, as: :method - expose :action_button_title, as: :button_title + expose :action_icon, as: :icon, documentation: { type: 'string', example: 'cancel' } + expose :action_title, as: :title, documentation: { type: 'string', example: 'Cancel' } + expose :action_path, as: :path, documentation: { type: 'string', example: '/namespace1/project1/-/jobs/2/cancel' } + expose :action_method, as: :method, documentation: { type: 'string', example: 'post' } + expose :action_button_title, as: :button_title, documentation: { type: 'string', example: 'Cancel this job' } end end diff --git a/app/serializers/diff_file_entity.rb b/app/serializers/diff_file_entity.rb index 9f8628fe849..aa43b9861d3 100644 --- a/app/serializers/diff_file_entity.rb +++ b/app/serializers/diff_file_entity.rb @@ -55,17 +55,9 @@ class DiffFileEntity < DiffFileBaseEntity end # Used for inline diffs - expose :highlighted_diff_lines, using: DiffLineEntity, if: -> (diff_file, options) { inline_diff_view?(options) && diff_file.text? } do |diff_file| - highlighted_diff_lines_for(diff_file, options) - end + expose :diff_lines_for_serializer, as: :highlighted_diff_lines, using: DiffLineEntity, if: -> (diff_file, options) { inline_diff_view?(options) && diff_file.text? } - expose :is_fully_expanded do |diff_file| - if conflict_file(options, diff_file) - false - else - diff_file.fully_expanded? - end - end + expose :fully_expanded?, as: :is_fully_expanded # Used for parallel diffs expose :parallel_diff_lines, using: DiffLineParallelEntity, if: -> (diff_file, options) { parallel_diff_view?(options) && diff_file.text? } @@ -88,15 +80,6 @@ class DiffFileEntity < DiffFileBaseEntity # If nothing is present, inline will be the default. options.fetch(:diff_view, :inline).to_sym end - - def highlighted_diff_lines_for(diff_file, options) - file = conflict_file(options, diff_file) || diff_file - - file.diff_lines_for_serializer - rescue Gitlab::Git::Conflict::Parser::UnmergeableFile - # Fallback to diff_file as it means that conflict lines can't be parsed due to limit - diff_file.diff_lines_for_serializer - end end DiffFileEntity.prepend_mod diff --git a/app/serializers/diffs_entity.rb b/app/serializers/diffs_entity.rb index c818fcd6215..759d1e0f10a 100644 --- a/app/serializers/diffs_entity.rb +++ b/app/serializers/diffs_entity.rb @@ -74,7 +74,7 @@ class DiffsEntity < Grape::Entity options.merge( submodule_links: submodule_links, code_navigation_path: code_navigation_path(diffs), - conflicts: conflicts(allow_tree_conflicts: options[:allow_tree_conflicts]) + conflicts: (conflicts(allow_tree_conflicts: true) if options[:merge_conflicts_in_diff]) ) ) end diff --git a/app/serializers/diffs_metadata_entity.rb b/app/serializers/diffs_metadata_entity.rb index 8c226130f6e..ace5105dda5 100644 --- a/app/serializers/diffs_metadata_entity.rb +++ b/app/serializers/diffs_metadata_entity.rb @@ -6,7 +6,7 @@ class DiffsMetadataEntity < DiffsEntity DiffFileMetadataEntity.represent( diffs.raw_diff_files(sorted: true), options.merge( - conflicts: conflicts(allow_tree_conflicts: options[:allow_tree_conflicts]) + conflicts: (conflicts(allow_tree_conflicts: true) if options[:merge_conflicts_in_diff]) ) ) end diff --git a/app/serializers/environment_serializer.rb b/app/serializers/environment_serializer.rb index 22839ba3099..46d5a488aea 100644 --- a/app/serializers/environment_serializer.rb +++ b/app/serializers/environment_serializer.rb @@ -43,7 +43,7 @@ class EnvironmentSerializer < BaseSerializer # immediately. items = @paginator.paginate(items) if paginated? - environments = batch_load(resource.where(id: items.map(&:last_id))) + environments = batch_load(Environment.where(id: items.map(&:last_id))) environments_by_id = environments.index_by(&:id) items.map do |item| @@ -52,15 +52,13 @@ class EnvironmentSerializer < BaseSerializer end def batch_load(resource) - temp_deployment_associations = deployment_associations - resource = resource.preload(environment_associations) Preloaders::Environments::DeploymentPreloader.new(resource) - .execute_with_union(:last_deployment, temp_deployment_associations) + .execute_with_union(:last_deployment, deployment_associations) Preloaders::Environments::DeploymentPreloader.new(resource) - .execute_with_union(:upcoming_deployment, temp_deployment_associations) + .execute_with_union(:upcoming_deployment, deployment_associations) resource.to_a.tap do |environments| environments.each do |environment| diff --git a/app/serializers/group_child_serializer.rb b/app/serializers/group_child_serializer.rb index 789707c2c9b..54e65752163 100644 --- a/app/serializers/group_child_serializer.rb +++ b/app/serializers/group_child_serializer.rb @@ -39,12 +39,13 @@ class GroupChildSerializer < BaseSerializer def represent_hierarchy(hierarchy, opts) serializer = self.class.new(params) - if hierarchy.is_a?(Hash) + case hierarchy + when Hash hierarchy.map do |parent, children| serializer.represent(parent, opts) .merge(children: Array.wrap(serializer.represent_hierarchy(children, opts))) end - elsif hierarchy.is_a?(Array) + when Array hierarchy.flat_map { |child| serializer.represent_hierarchy(child, opts) } else serializer.represent(hierarchy, opts) diff --git a/app/serializers/integrations/event_entity.rb b/app/serializers/integrations/event_entity.rb index 91bd91dd941..1cbd6114581 100644 --- a/app/serializers/integrations/event_entity.rb +++ b/app/serializers/integrations/event_entity.rb @@ -25,6 +25,9 @@ module Integrations expose :value do |event| integration.event_channel_value(event) end + expose :placeholder do |_event| + integration.default_channel_placeholder + end end private diff --git a/app/serializers/integrations/field_entity.rb b/app/serializers/integrations/field_entity.rb index 697b53a737e..1c548cfab78 100644 --- a/app/serializers/integrations/field_entity.rb +++ b/app/serializers/integrations/field_entity.rb @@ -22,6 +22,8 @@ module Integrations 'true' elsif field[:type] == 'checkbox' ActiveRecord::Type::Boolean.new.deserialize(value).to_s + elsif field[:name] == 'webhook' && integration.chat? + BaseChatNotification::SECRET_MASK if value.present? else value end diff --git a/app/serializers/merge_request_noteable_entity.rb b/app/serializers/merge_request_noteable_entity.rb index 07d7d19d1f3..306bac7daae 100644 --- a/app/serializers/merge_request_noteable_entity.rb +++ b/app/serializers/merge_request_noteable_entity.rb @@ -66,7 +66,7 @@ class MergeRequestNoteableEntity < IssuableEntity expose :project_id expose :archived_project_docs_path, if: -> (merge_request) { merge_request.project.archived? } do |merge_request| - help_page_path('user/project/settings/index.md', anchor: 'archiving-a-project') + help_page_path('user/project/settings/index.md', anchor: 'archive-a-project') end private diff --git a/app/serializers/merge_request_poll_cached_widget_entity.rb b/app/serializers/merge_request_poll_cached_widget_entity.rb index 0c5af67bcda..33079905ed2 100644 --- a/app/serializers/merge_request_poll_cached_widget_entity.rb +++ b/app/serializers/merge_request_poll_cached_widget_entity.rb @@ -3,11 +3,9 @@ class MergeRequestPollCachedWidgetEntity < IssuableEntity include MergeRequestMetricsHelper - expose :auto_merge_enabled expose :state expose :merged_commit_sha expose :short_merged_commit_sha - expose :merge_error expose :merge_user_id expose :source_branch expose :source_project_id @@ -16,15 +14,10 @@ class MergeRequestPollCachedWidgetEntity < IssuableEntity expose :target_project_id expose :squash expose :rebase_in_progress?, as: :rebase_in_progress - expose :commits_count + expose :default_squash_commit_message expose :merge_ongoing?, as: :merge_ongoing - expose :draft?, as: :draft - expose :draft?, as: :work_in_progress - expose :cannot_be_merged?, as: :has_conflicts - expose :can_be_merged?, as: :can_be_merged expose :remove_source_branch?, as: :remove_source_branch expose :source_branch_exists?, as: :source_branch_exists - expose :branch_missing?, as: :branch_missing expose :merge_status do |merge_request| merge_request.check_mergeability(async: true) diff --git a/app/serializers/merge_request_poll_widget_entity.rb b/app/serializers/merge_request_poll_widget_entity.rb index 40bb905c5c9..ab180b35b29 100644 --- a/app/serializers/merge_request_poll_widget_entity.rb +++ b/app/serializers/merge_request_poll_widget_entity.rb @@ -11,7 +11,6 @@ class MergeRequestPollWidgetEntity < Grape::Entity merge_request.source_project.present? && ProtectedBranch.protected?(merge_request.source_project, merge_request.source_branch) end expose :allow_collaboration - expose :should_be_rebased?, as: :should_be_rebased expose :ff_only_enabled do |merge_request| merge_request.project.merge_requests_ff_only_enabled end @@ -31,15 +30,6 @@ class MergeRequestPollWidgetEntity < Grape::Entity merge_request.default_merge_commit_message(include_description: true) end - # Booleans - expose :mergeable_discussions_state?, as: :mergeable_discussions_state do |merge_request| - merge_request.mergeable_discussions_state? - end - - expose :project_archived do |merge_request| - merge_request.project.archived? - end - expose :only_allow_merge_if_pipeline_succeeds do |merge_request| merge_request.project.only_allow_merge_if_pipeline_succeeds? end diff --git a/app/serializers/merge_requests/pipeline_entity.rb b/app/serializers/merge_requests/pipeline_entity.rb index f4fb01604d0..76e75a8ca6d 100644 --- a/app/serializers/merge_requests/pipeline_entity.rb +++ b/app/serializers/merge_requests/pipeline_entity.rb @@ -5,6 +5,7 @@ class MergeRequests::PipelineEntity < Grape::Entity expose :id expose :active?, as: :active + expose :name, if: -> (pipeline, _) { Feature.enabled?(:pipeline_name, pipeline.project) } expose :path do |pipeline| project_pipeline_path(pipeline.project, pipeline) @@ -17,8 +18,12 @@ class MergeRequests::PipelineEntity < Grape::Entity expose :commit, using: CommitEntity expose :details do - expose :name do |pipeline| - pipeline.present.name + expose :event_type_name do |pipeline| + pipeline.present.event_type_name + end + + expose :name do |pipeline| # To be removed in 15.7 + pipeline.present.event_type_name end expose :artifacts do |pipeline, options| diff --git a/app/serializers/paginated_diff_entity.rb b/app/serializers/paginated_diff_entity.rb index c656cff9dd7..b79a0937659 100644 --- a/app/serializers/paginated_diff_entity.rb +++ b/app/serializers/paginated_diff_entity.rb @@ -17,7 +17,7 @@ class PaginatedDiffEntity < Grape::Entity options.merge( submodule_links: submodule_links, code_navigation_path: code_navigation_path(diffs), - conflicts: conflicts(allow_tree_conflicts: options[:allow_tree_conflicts]) + conflicts: (conflicts(allow_tree_conflicts: true) if options[:merge_conflicts_in_diff]) ) ) end diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb index 9cfc81e8705..b738438a78f 100644 --- a/app/serializers/pipeline_serializer.rb +++ b/app/serializers/pipeline_serializer.rb @@ -40,6 +40,7 @@ class PipelineSerializer < BaseSerializer def preloaded_relations [ + :pipeline_metadata, :cancelable_statuses, :retryable_builds, :stages, diff --git a/app/serializers/project_entity.rb b/app/serializers/project_entity.rb index 60c4ba135d6..77e2115fbe2 100644 --- a/app/serializers/project_entity.rb +++ b/app/serializers/project_entity.rb @@ -3,14 +3,14 @@ class ProjectEntity < Grape::Entity include RequestAwareEntity - expose :id - expose :name + expose :id, documentation: { type: 'integer', example: 1 } + expose :name, documentation: { type: 'string', example: 'GitLab' } - expose :full_path do |project| + expose :full_path, documentation: { type: 'string', example: 'gitlab-org/gitlab' } do |project| project_path(project) end - expose :full_name do |project| + expose :full_name, documentation: { type: 'string', example: 'GitLab Org / GitLab' } do |project| project.full_name end end diff --git a/app/serializers/project_import_entity.rb b/app/serializers/project_import_entity.rb index 9b51af685e7..a3dbff3dc0b 100644 --- a/app/serializers/project_import_entity.rb +++ b/app/serializers/project_import_entity.rb @@ -3,11 +3,13 @@ class ProjectImportEntity < ProjectEntity include ImportHelper - expose :import_source - expose :import_status - expose :human_import_status_name + expose :import_source, documentation: { type: 'string', example: 'source/source-repo' } + expose :import_status, documentation: { + type: 'string', example: 'scheduled', values: %w[scheduled started finished failed canceled] + } + expose :human_import_status_name, documentation: { type: 'string', example: 'canceled' } - expose :provider_link do |project, options| + expose :provider_link, documentation: { type: 'string', example: '/source/source-repo' } do |project, options| provider_project_link_url(options[:provider_url], project[:import_source]) end end diff --git a/app/serializers/test_case_entity.rb b/app/serializers/test_case_entity.rb index 8a5fadf53a6..1a872274cbf 100644 --- a/app/serializers/test_case_entity.rb +++ b/app/serializers/test_case_entity.rb @@ -3,15 +3,20 @@ class TestCaseEntity < Grape::Entity include API::Helpers::RelatedResourcesHelpers - expose :status - expose :name, default: "(No name)" - expose :classname - expose :file - expose :execution_time - expose :system_output - expose :stack_trace - expose :recent_failures - expose :attachment_url, if: -> (*) { can_read_screenshots? } do |test_case| + expose :status, documentation: { type: 'string', example: 'success' } + expose :name, default: "(No name)", + documentation: { type: 'string', example: 'Security Reports can create an auto-remediation MR' } + expose :classname, documentation: { type: 'string', example: 'vulnerability_management_spec' } + expose :file, documentation: { type: 'string', example: './spec/test_spec.rb' } + expose :execution_time, documentation: { type: 'integer', example: 180 } + expose :system_output, documentation: { type: 'string', example: 'Failure/Error: is_expected.to eq(3)' } + expose :stack_trace, documentation: { type: 'string', example: 'Failure/Error: is_expected.to eq(3)' } + expose :recent_failures, documentation: { example: { count: 3, base_branch: 'develop' } } + expose( + :attachment_url, + if: -> (*) { can_read_screenshots? }, + documentation: { type: 'string', example: 'http://localhost/namespace1/project1/-/jobs/1/artifacts/file/some/path.png' } + ) do |test_case| expose_url(test_case.attachment_url) end diff --git a/app/serializers/test_report_entity.rb b/app/serializers/test_report_entity.rb index 9eb487da60a..0ff1c671f53 100644 --- a/app/serializers/test_report_entity.rb +++ b/app/serializers/test_report_entity.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true class TestReportEntity < Grape::Entity - expose :total_time - expose :total_count + expose :total_time, documentation: { type: 'integer', example: 180 } + expose :total_count, documentation: { type: 'integer', example: 1 } - expose :success_count - expose :failed_count - expose :skipped_count - expose :error_count + expose :success_count, documentation: { type: 'integer', example: 1 } + expose :failed_count, documentation: { type: 'integer', example: 0 } + expose :skipped_count, documentation: { type: 'integer', example: 0 } + expose :error_count, documentation: { type: 'integer', example: 0 } - expose :test_suites, using: TestSuiteEntity do |report| + expose :test_suites, using: TestSuiteEntity, documentation: { is_array: true } do |report| report.test_suites.values end end diff --git a/app/serializers/test_report_summary_entity.rb b/app/serializers/test_report_summary_entity.rb index bc73c49092f..f712b9f5500 100644 --- a/app/serializers/test_report_summary_entity.rb +++ b/app/serializers/test_report_summary_entity.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class TestReportSummaryEntity < Grape::Entity - expose :total + expose :total, documentation: { type: 'integer', example: 3363 } expose :test_suites, using: TestSuiteSummaryEntity do |summary| summary.test_suites.values diff --git a/app/serializers/test_suite_entity.rb b/app/serializers/test_suite_entity.rb index 15eb2891b22..a31b1f3ab9b 100644 --- a/app/serializers/test_suite_entity.rb +++ b/app/serializers/test_suite_entity.rb @@ -1,18 +1,19 @@ # frozen_string_literal: true class TestSuiteEntity < Grape::Entity - expose :name - expose :total_time - expose :total_count + expose :name, documentation: { type: 'string', example: 'test' } + expose :total_time, documentation: { type: 'integer', example: 1904 } + expose :total_count, documentation: { type: 'integer', example: 3363 } - expose :success_count - expose :failed_count - expose :skipped_count - expose :error_count + expose :success_count, documentation: { type: 'integer', example: 3351 } + expose :failed_count, documentation: { type: 'integer', example: 0 } + expose :skipped_count, documentation: { type: 'integer', example: 12 } + expose :error_count, documentation: { type: 'integer', example: 0 } with_options if: -> (_, opts) { opts[:details] } do |test_suite| - expose :suite_error - expose :test_cases, using: TestCaseEntity do |test_suite| + expose :suite_error, + documentation: { type: 'string', example: 'JUnit XML parsing failed: 1:1: FATAL: Document is empty' } + expose :test_cases, using: TestCaseEntity, documentation: { is_array: true } do |test_suite| test_suite.suite_error ? [] : test_suite.sorted.test_cases.values.flat_map(&:values) end end diff --git a/app/serializers/test_suite_summary_entity.rb b/app/serializers/test_suite_summary_entity.rb index 228c6e499fe..3a9ccb22713 100644 --- a/app/serializers/test_suite_summary_entity.rb +++ b/app/serializers/test_suite_summary_entity.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true class TestSuiteSummaryEntity < TestSuiteEntity - expose :build_ids do |summary| + expose :build_ids, documentation: { type: 'integer', is_array: true, example: [66004] } do |summary| summary.build_ids end - expose :suite_error + expose :suite_error, + documentation: { type: 'string', example: 'JUnit XML parsing failed: 1:1: FATAL: Document is empty' } end |