diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /app/serializers | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/analytics/cycle_analytics/stage_entity.rb | 16 | ||||
-rw-r--r-- | app/serializers/build_details_entity.rb | 6 | ||||
-rw-r--r-- | app/serializers/build_serializer.rb | 10 | ||||
-rw-r--r-- | app/serializers/ci/job_entity.rb | 96 | ||||
-rw-r--r-- | app/serializers/ci/job_serializer.rb | 12 | ||||
-rw-r--r-- | app/serializers/ci/pipeline_entity.rb | 4 | ||||
-rw-r--r-- | app/serializers/deployment_entity.rb | 10 | ||||
-rw-r--r-- | app/serializers/deployment_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/diff_file_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/job_entity.rb | 94 | ||||
-rw-r--r-- | app/serializers/job_group_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/member_entity.rb | 6 | ||||
-rw-r--r-- | app/serializers/merge_request_widget_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/merge_requests/pipeline_entity.rb | 4 | ||||
-rw-r--r-- | app/serializers/note_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/stage_entity.rb | 4 |
16 files changed, 152 insertions, 120 deletions
diff --git a/app/serializers/analytics/cycle_analytics/stage_entity.rb b/app/serializers/analytics/cycle_analytics/stage_entity.rb index c5cc8c89fb7..cfbf6f60e38 100644 --- a/app/serializers/analytics/cycle_analytics/stage_entity.rb +++ b/app/serializers/analytics/cycle_analytics/stage_entity.rb @@ -3,6 +3,10 @@ module Analytics module CycleAnalytics class StageEntity < Grape::Entity + include ActionView::Context + include LabelsHelper + include ActionView::Helpers::TagHelper + expose :title expose :hidden expose :legend @@ -43,10 +47,20 @@ module Analytics html_description(object.end_event) end + # Avoid including ActionView::Helpers::UrlHelper + def link_to(*args) + ActionController::Base.helpers.link_to(*args) + end + private def html_description(event) - Banzai::Renderer.render(event.markdown_description, { group: object.group, project: nil }) + options = {} + if event.label_based? + options[:label_html] = render_label(event.label, link: '', small: true, tooltip: true) + end + + content_tag(:p) { event.html_description(options).html_safe } end end end diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb index 4615f471639..9fd35faf0b7 100644 --- a/app/serializers/build_details_entity.rb +++ b/app/serializers/build_details_entity.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -class BuildDetailsEntity < JobEntity - expose :coverage, :erased_at, :duration +class BuildDetailsEntity < Ci::JobEntity + expose :coverage, :erased_at, :finished_at, :duration expose :tag_list, as: :tags expose :has_trace?, as: :has_trace expose :stage @@ -109,6 +109,8 @@ class BuildDetailsEntity < JobEntity private + alias_method :build, :object + def build_failed_issue_options { title: "Job Failed ##{build.id}", description: "Job [##{build.id}](#{project_job_url(project, build)}) failed for #{build.sha}:\n" } diff --git a/app/serializers/build_serializer.rb b/app/serializers/build_serializer.rb deleted file mode 100644 index 0649fdad6a8..00000000000 --- a/app/serializers/build_serializer.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -class BuildSerializer < BaseSerializer - entity JobEntity - - def represent_status(resource) - data = represent(resource, { only: [:status] }) - data.fetch(:status, {}) - end -end diff --git a/app/serializers/ci/job_entity.rb b/app/serializers/ci/job_entity.rb new file mode 100644 index 00000000000..fca3dec74d4 --- /dev/null +++ b/app/serializers/ci/job_entity.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +module Ci + class JobEntity < Grape::Entity + include RequestAwareEntity + + expose :id + expose :name + + expose :started?, as: :started + expose :complete?, as: :complete + expose :archived?, as: :archived + + # bridge jobs don't have build details pages + expose :build_path, if: ->(job) { !job.is_a?(Ci::Bridge) } do |job| + job_path(job) + end + + expose :retry_path, if: -> (*) { retryable? } do |job| + path_to(:retry_namespace_project_job, job) + end + + expose :cancel_path, if: -> (*) { cancelable? } do |job| + path_to( + :cancel_namespace_project_job, + job, + { continue: { to: job_path(job) } } + ) + end + + expose :play_path, if: -> (*) { playable? } do |job| + path_to(:play_namespace_project_job, job) + end + + expose :unschedule_path, if: -> (*) { scheduled? } do |job| + path_to(:unschedule_namespace_project_job, job) + end + + expose :playable?, as: :playable + expose :scheduled?, as: :scheduled + expose :scheduled_at, if: -> (*) { scheduled? } + expose :created_at + expose :updated_at + expose :detailed_status, as: :status, with: DetailedStatusEntity + expose :callout_message, if: -> (*) { failed? && !job.script_failure? } + expose :recoverable, if: -> (*) { failed? } + + private + + alias_method :job, :object + + def cancelable? + job.cancelable? && can?(request.current_user, :update_build, job) + end + + def retryable? + job.retryable? && can?(request.current_user, :update_build, job) + end + + def playable? + job.playable? && can?(request.current_user, :update_build, job) + end + + def scheduled? + job.scheduled? + end + + def detailed_status + job.detailed_status(request.current_user) + end + + def path_to(route, job, params = {}) + send("#{route}_path", job.project.namespace, job.project, job, params) # rubocop:disable GitlabSecurity/PublicSend + end + + def job_path(job) + job.target_url || path_to(:namespace_project_job, job) + end + + def failed? + job.failed? + end + + def callout_message + job_presenter.callout_failure_message + end + + def recoverable + job_presenter.recoverable? + end + + def job_presenter + @job_presenter ||= job.present + end + end +end diff --git a/app/serializers/ci/job_serializer.rb b/app/serializers/ci/job_serializer.rb new file mode 100644 index 00000000000..01f9e223943 --- /dev/null +++ b/app/serializers/ci/job_serializer.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Ci + class JobSerializer < BaseSerializer + entity Ci::JobEntity + + def represent_status(resource) + data = represent(resource, { only: [:status] }) + data.fetch(:status, {}) + end + end +end diff --git a/app/serializers/ci/pipeline_entity.rb b/app/serializers/ci/pipeline_entity.rb index a5af543f49f..20aeb978520 100644 --- a/app/serializers/ci/pipeline_entity.rb +++ b/app/serializers/ci/pipeline_entity.rb @@ -4,7 +4,7 @@ class Ci::PipelineEntity < Grape::Entity include RequestAwareEntity include Gitlab::Utils::StrongMemoize - delegate :name, :failure_reason, to: :presented_pipeline + delegate :name, :failure_reason, :coverage, to: :presented_pipeline expose :id expose :iid @@ -82,7 +82,7 @@ class Ci::PipelineEntity < Grape::Entity project_pipeline_path(pipeline.project, pipeline) end - expose :failed_builds, if: -> (*) { can_retry? }, using: JobEntity do |pipeline| + expose :failed_builds, if: -> (*) { can_retry? }, using: Ci::JobEntity do |pipeline| pipeline.failed_builds.each do |build| build.project = pipeline.project end diff --git a/app/serializers/deployment_entity.rb b/app/serializers/deployment_entity.rb index 08a939e86c5..7a2fba73f3a 100644 --- a/app/serializers/deployment_entity.rb +++ b/app/serializers/deployment_entity.rb @@ -22,12 +22,14 @@ class DeploymentEntity < Grape::Entity expose :deployed_at expose :tag expose :last? + expose :last?, as: :is_last + expose :deployed_by, as: :user, using: UserEntity expose :deployable, if: -> (deployment) { deployment.deployable.present? } do |deployment, opts| deployment.deployable.yield_self do |deployable| if include_details? - JobEntity.represent(deployable, opts) + Ci::JobEntity.represent(deployable, opts) elsif can_read_deployables? { name: deployable.name, build_path: project_job_path(deployable.project, deployable) } @@ -36,10 +38,10 @@ class DeploymentEntity < Grape::Entity end expose :commit, using: CommitEntity, if: -> (*) { include_details? } - expose :manual_actions, using: JobEntity, if: -> (*) { include_details? && can_create_deployment? } - expose :scheduled_actions, using: JobEntity, if: -> (*) { include_details? && can_create_deployment? } + expose :manual_actions, using: Ci::JobEntity, if: -> (*) { include_details? && can_create_deployment? } + expose :scheduled_actions, using: Ci::JobEntity, if: -> (*) { include_details? && can_create_deployment? } expose :playable_build, if: -> (deployment) { include_details? && can_create_deployment? && deployment.playable_build } do |deployment, options| - JobEntity.represent(deployment.playable_build, options.merge(only: [:play_path, :retry_path])) + Ci::JobEntity.represent(deployment.playable_build, options.merge(only: [:play_path, :retry_path])) end expose :cluster do |deployment, options| diff --git a/app/serializers/deployment_serializer.rb b/app/serializers/deployment_serializer.rb index b48037dd53f..7710efed3ab 100644 --- a/app/serializers/deployment_serializer.rb +++ b/app/serializers/deployment_serializer.rb @@ -4,7 +4,7 @@ class DeploymentSerializer < BaseSerializer entity DeploymentEntity def represent_concise(resource, opts = {}) - opts[:only] = [:iid, :id, :sha, :created_at, :deployed_at, :tag, :last?, :id, ref: [:name]] + opts[:only] = [:iid, :id, :sha, :created_at, :deployed_at, :tag, :last?, :is_last, :id, ref: [:name]] represent(resource, opts) end end diff --git a/app/serializers/diff_file_entity.rb b/app/serializers/diff_file_entity.rb index 7eca56b2f48..ef856ee0116 100644 --- a/app/serializers/diff_file_entity.rb +++ b/app/serializers/diff_file_entity.rb @@ -90,3 +90,5 @@ class DiffFileEntity < DiffFileBaseEntity options.fetch(:diff_view, :inline).to_sym end end + +DiffFileEntity.prepend_mod diff --git a/app/serializers/job_entity.rb b/app/serializers/job_entity.rb deleted file mode 100644 index eb8622edb38..00000000000 --- a/app/serializers/job_entity.rb +++ /dev/null @@ -1,94 +0,0 @@ -# frozen_string_literal: true - -class JobEntity < Grape::Entity - include RequestAwareEntity - - expose :id - expose :name - - expose :started?, as: :started - expose :complete?, as: :complete - expose :archived?, as: :archived - - # bridge jobs don't have build detail pages - expose :build_path, if: ->(build) { !build.is_a?(Ci::Bridge) } do |build| - build_path(build) - end - - expose :retry_path, if: -> (*) { retryable? } do |build| - path_to(:retry_namespace_project_job, build) - end - - expose :cancel_path, if: -> (*) { cancelable? } do |build| - path_to( - :cancel_namespace_project_job, - build, - { continue: { to: build_path(build) } } - ) - end - - expose :play_path, if: -> (*) { playable? } do |build| - path_to(:play_namespace_project_job, build) - end - - expose :unschedule_path, if: -> (*) { scheduled? } do |build| - path_to(:unschedule_namespace_project_job, build) - end - - expose :playable?, as: :playable - expose :scheduled?, as: :scheduled - expose :scheduled_at, if: -> (*) { scheduled? } - expose :created_at - expose :updated_at - expose :detailed_status, as: :status, with: DetailedStatusEntity - expose :callout_message, if: -> (*) { failed? && !build.script_failure? } - expose :recoverable, if: -> (*) { failed? } - - private - - alias_method :build, :object - - def cancelable? - build.cancelable? && can?(request.current_user, :update_build, build) - end - - def retryable? - build.retryable? && can?(request.current_user, :update_build, build) - end - - def playable? - build.playable? && can?(request.current_user, :update_build, build) - end - - def scheduled? - build.scheduled? - end - - def detailed_status - build.detailed_status(request.current_user) - end - - def path_to(route, build, params = {}) - send("#{route}_path", build.project.namespace, build.project, build, params) # rubocop:disable GitlabSecurity/PublicSend - end - - def build_path(build) - build.target_url || path_to(:namespace_project_job, build) - end - - def failed? - build.failed? - end - - def callout_message - build_presenter.callout_failure_message - end - - def recoverable - build_presenter.recoverable? - end - - def build_presenter - @build_presenter ||= build.present - end -end diff --git a/app/serializers/job_group_entity.rb b/app/serializers/job_group_entity.rb index 0db7624b3f7..3597d5531fa 100644 --- a/app/serializers/job_group_entity.rb +++ b/app/serializers/job_group_entity.rb @@ -6,7 +6,7 @@ class JobGroupEntity < Grape::Entity expose :name expose :size expose :detailed_status, as: :status, with: DetailedStatusEntity - expose :jobs, with: JobEntity + expose :jobs, with: Ci::JobEntity private diff --git a/app/serializers/member_entity.rb b/app/serializers/member_entity.rb index d7221109ecb..f2f97f560e0 100644 --- a/app/serializers/member_entity.rb +++ b/app/serializers/member_entity.rb @@ -63,6 +63,12 @@ class MemberEntity < Grape::Entity member.respond_to?(:invited_user_state) ? member.invited_user_state : "" end end + + private + + def current_user + options[:current_user] + end end MemberEntity.prepend_mod_with('MemberEntity') diff --git a/app/serializers/merge_request_widget_entity.rb b/app/serializers/merge_request_widget_entity.rb index bd60d60c8db..b9c71e6d97b 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -73,7 +73,7 @@ class MergeRequestWidgetEntity < Grape::Entity end expose :user_callouts_path do |_merge_request| - user_callouts_path + callouts_path end expose :suggest_pipeline_feature_id do |_merge_request| diff --git a/app/serializers/merge_requests/pipeline_entity.rb b/app/serializers/merge_requests/pipeline_entity.rb index bdf5cb160b2..f4fb01604d0 100644 --- a/app/serializers/merge_requests/pipeline_entity.rb +++ b/app/serializers/merge_requests/pipeline_entity.rb @@ -43,7 +43,9 @@ class MergeRequests::PipelineEntity < Grape::Entity # 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 # disabling of this specific field whenever necessary. - expose :coverage, unless: proc { options[:disable_coverage] } + expose :coverage, unless: proc { options[:disable_coverage] } do |pipeline| + pipeline.present.coverage + end expose :ref do expose :branch?, as: :branch diff --git a/app/serializers/note_entity.rb b/app/serializers/note_entity.rb index 8f189f14dea..58ad5812801 100644 --- a/app/serializers/note_entity.rb +++ b/app/serializers/note_entity.rb @@ -51,7 +51,7 @@ class NoteEntity < API::Entities::Note SystemNoteHelper.system_note_icon_name(note) end - expose :outdated_line_change_path, if: -> (note, _) { note.system? && note.change_position&.line_range && Feature.enabled?(:display_outdated_line_diff, note.project, default_enabled: :yaml) } do |note| + expose :outdated_line_change_path, if: -> (note, _) { note.show_outdated_changes? } do |note| outdated_line_change_namespace_project_note_path(namespace_id: note.project.namespace, project_id: note.project, id: note) end diff --git a/app/serializers/stage_entity.rb b/app/serializers/stage_entity.rb index 0aadcd01a43..548ff577863 100644 --- a/app/serializers/stage_entity.rb +++ b/app/serializers/stage_entity.rb @@ -15,13 +15,13 @@ class StageEntity < Grape::Entity expose :latest_statuses, if: -> (_, opts) { opts[:details] }, - with: JobEntity do |stage| + with: Ci::JobEntity do |stage| latest_statuses end expose :retried, if: -> (_, opts) { opts[:retried] }, - with: JobEntity do |stage| + with: Ci::JobEntity do |stage| retried_statuses end |