diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /app/presenters | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'app/presenters')
10 files changed, 85 insertions, 154 deletions
diff --git a/app/presenters/alert_management/alert_presenter.rb b/app/presenters/alert_management/alert_presenter.rb index 5bfa6dee18b..5debe6d5dbd 100644 --- a/app/presenters/alert_management/alert_presenter.rb +++ b/app/presenters/alert_management/alert_presenter.rb @@ -6,7 +6,10 @@ module AlertManagement include IncidentManagement::Settings include ActionView::Helpers::UrlHelper - MARKDOWN_LINE_BREAK = " \n".freeze + MARKDOWN_LINE_BREAK = " \n" + HORIZONTAL_LINE = "\n\n---\n\n" + + delegate :metrics_dashboard_url, :runbook, to: :parsed_payload def initialize(alert, _attributes = {}) super @@ -16,52 +19,37 @@ module AlertManagement end def issue_description - horizontal_line = "\n\n---\n\n" - [ issue_summary_markdown, alert_markdown, incident_management_setting.issue_template_content - ].compact.join(horizontal_line) + ].compact.join(HORIZONTAL_LINE) end def start_time started_at&.strftime('%d %B %Y, %-l:%M%p (%Z)') end - def issue_summary_markdown - <<~MARKDOWN.chomp - #### Summary - - #{metadata_list} - #{alert_details}#{metric_embed_for_alert} - MARKDOWN - end - - def runbook - strong_memoize(:runbook) do - payload&.dig('runbook') - end - end - - def metrics_dashboard_url; end - def details_url details_project_alert_management_url(project, alert.iid) end + def details + Gitlab::Utils::InlineHash.merge_keys(payload) + end + private attr_reader :alert, :project + delegate :alert_markdown, :full_query, to: :parsed_payload - def alerting_alert - strong_memoize(:alerting_alert) do - Gitlab::Alerting::Alert.new(project: project, payload: alert.payload).present - end + def issue_summary_markdown + <<~MARKDOWN.chomp + #{metadata_list} + #{metric_embed_for_alert} + MARKDOWN end - def alert_markdown; end - def metadata_list metadata = [] @@ -77,27 +65,10 @@ module AlertManagement metadata.join(MARKDOWN_LINE_BREAK) end - def alert_details - if details.present? - <<~MARKDOWN.chomp - - #### Alert Details - - #{details_list} - MARKDOWN - end - end - - def details_list - alert.details - .map { |label, value| list_item(label, value) } - .join(MARKDOWN_LINE_BREAK) + def metric_embed_for_alert + "\n[](#{metrics_dashboard_url})" if metrics_dashboard_url end - def metric_embed_for_alert; end - - def full_query; end - def list_item(key, value) "**#{key}:** #{value}".strip end diff --git a/app/presenters/alert_management/prometheus_alert_presenter.rb b/app/presenters/alert_management/prometheus_alert_presenter.rb deleted file mode 100644 index 6b8c8183f08..00000000000 --- a/app/presenters/alert_management/prometheus_alert_presenter.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -module AlertManagement - class PrometheusAlertPresenter < AlertManagement::AlertPresenter - def runbook - strong_memoize(:runbook) do - payload&.dig('annotations', 'runbook') - end - end - - def metrics_dashboard_url - alerting_alert.metrics_dashboard_url - end - - private - - def alert_markdown - alerting_alert.alert_markdown - end - - def details_list - alerting_alert.annotation_list - end - - def metric_embed_for_alert - alerting_alert.metric_embed_for_alert - end - - def full_query - alerting_alert.full_query - end - end -end diff --git a/app/presenters/ci/pipeline_artifacts/code_coverage_presenter.rb b/app/presenters/ci/pipeline_artifacts/code_coverage_presenter.rb new file mode 100644 index 00000000000..098e839132c --- /dev/null +++ b/app/presenters/ci/pipeline_artifacts/code_coverage_presenter.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Ci + module PipelineArtifacts + class CodeCoveragePresenter < ProcessablePresenter + include Gitlab::Utils::StrongMemoize + + def for_files(filenames) + coverage_files = raw_report["files"].select { |key| filenames.include?(key) } + + { files: coverage_files } + end + + private + + def raw_report + strong_memoize(:raw_report) do + self.each_blob do |blob| + Gitlab::Json.parse(blob) + end + end + end + end + end +end diff --git a/app/presenters/clusters/cluster_presenter.rb b/app/presenters/clusters/cluster_presenter.rb index 25693af4881..541a6363edd 100644 --- a/app/presenters/clusters/cluster_presenter.rb +++ b/app/presenters/clusters/cluster_presenter.rb @@ -79,7 +79,7 @@ module Clusters { 'clusters-path': clusterable.index_path, 'dashboard-endpoint': clusterable.metrics_dashboard_path(cluster), - 'documentation-path': help_page_path('user/project/clusters/index', anchor: 'monitoring-your-kubernetes-cluster-ultimate'), + 'documentation-path': help_page_path('user/project/clusters/index', anchor: 'monitoring-your-kubernetes-cluster'), 'add-dashboard-documentation-path': help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'), 'empty-getting-started-svg-path': image_path('illustrations/monitoring/getting_started.svg'), 'empty-loading-svg-path': image_path('illustrations/monitoring/loading.svg'), diff --git a/app/presenters/commit_status_presenter.rb b/app/presenters/commit_status_presenter.rb index eaa7cf848cd..714dd232efb 100644 --- a/app/presenters/commit_status_presenter.rb +++ b/app/presenters/commit_status_presenter.rb @@ -20,7 +20,8 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated insufficient_bridge_permissions: 'This job could not be executed because of insufficient permissions to create a downstream pipeline', bridge_pipeline_is_child_pipeline: 'This job belongs to a child pipeline and cannot create further child pipelines', downstream_pipeline_creation_failed: 'The downstream pipeline could not be created', - secrets_provider_not_found: 'The secrets provider can not be found' + secrets_provider_not_found: 'The secrets provider can not be found', + reached_max_descendant_pipelines_depth: 'Maximum child pipeline depth has been reached' }.freeze private_constant :CALLOUT_FAILURE_MESSAGES diff --git a/app/presenters/dev_ops_score/metric_presenter.rb b/app/presenters/dev_ops_score/metric_presenter.rb index d22beefee54..e7363293435 100644 --- a/app/presenters/dev_ops_score/metric_presenter.rb +++ b/app/presenters/dev_ops_score/metric_presenter.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DevOpsScore +module DevOpsReport class MetricPresenter < Gitlab::View::Presenter::Simple def cards [ diff --git a/app/presenters/packages/conan/package_presenter.rb b/app/presenters/packages/conan/package_presenter.rb index 5141c450412..df770777ad1 100644 --- a/app/presenters/packages/conan/package_presenter.rb +++ b/app/presenters/packages/conan/package_presenter.rb @@ -3,13 +3,14 @@ module Packages module Conan class PackagePresenter + include API::Helpers::Packages::Conan::ApiHelpers include API::Helpers::RelatedResourcesHelpers include Gitlab::Utils::StrongMemoize attr_reader :params - def initialize(recipe, user, project, params = {}) - @recipe = recipe + def initialize(package, user, project, params = {}) + @package = package @user = user @project = project @params = params @@ -17,7 +18,10 @@ module Packages def recipe_urls map_package_files do |package_file| - build_recipe_file_url(package_file) if package_file.conan_file_metadatum.recipe_file? + next unless package_file.conan_file_metadatum.recipe_file? + + options = url_options(package_file) + recipe_file_url(options) end end @@ -31,7 +35,12 @@ module Packages map_package_files do |package_file| next unless package_file.conan_file_metadatum.package_file? && matching_reference?(package_file) - build_package_file_url(package_file) + options = url_options(package_file).merge( + conan_package_reference: package_file.conan_file_metadatum.conan_package_reference, + package_revision: package_file.conan_file_metadatum.package_revision + ) + + package_file_url(options) end end @@ -45,36 +54,21 @@ module Packages private - def build_recipe_file_url(package_file) - expose_url( - api_v4_packages_conan_v1_files_export_path( - package_name: package.name, - package_version: package.version, - package_username: package.conan_metadatum.package_username, - package_channel: package.conan_metadatum.package_channel, - recipe_revision: package_file.conan_file_metadatum.recipe_revision, - file_name: package_file.file_name - ) - ) - end - - def build_package_file_url(package_file) - expose_url( - api_v4_packages_conan_v1_files_package_path( - package_name: package.name, - package_version: package.version, - package_username: package.conan_metadatum.package_username, - package_channel: package.conan_metadatum.package_channel, - recipe_revision: package_file.conan_file_metadatum.recipe_revision, - conan_package_reference: package_file.conan_file_metadatum.conan_package_reference, - package_revision: package_file.conan_file_metadatum.package_revision, - file_name: package_file.file_name - ) - ) + def url_options(package_file) + { + package_name: @package.name, + package_version: @package.version, + package_username: @package.conan_metadatum.package_username, + package_channel: @package.conan_metadatum.package_channel, + file_name: package_file.file_name, + recipe_revision: package_file.conan_file_metadatum.recipe_revision.presence || ::Packages::Conan::FileMetadatum::DEFAULT_RECIPE_REVISION + } end def map_package_files package_files.to_a.map do |package_file| + next unless package_file.conan_file_metadatum + key = package_file.file_name value = yield(package_file) next unless key && value @@ -84,22 +78,9 @@ module Packages end def package_files - return unless package + return unless @package - @package_files ||= package.package_files.preload_conan_file_metadata - end - - def package - strong_memoize(:package) do - name, version = @recipe.split('@')[0].split('/') - - @project.packages - .conan - .with_name(name) - .with_version(version) - .order_created - .last - end + @package_files ||= @package.package_files.preload_conan_file_metadata end def matching_reference?(package_file) diff --git a/app/presenters/packages/nuget/search_results_presenter.rb b/app/presenters/packages/nuget/search_results_presenter.rb index 96c8fe7dd2a..dc391c380f3 100644 --- a/app/presenters/packages/nuget/search_results_presenter.rb +++ b/app/presenters/packages/nuget/search_results_presenter.rb @@ -49,7 +49,7 @@ module Packages def latest_version(packages) versions = packages.map(&:version).compact - VersionSorter.sort(versions).last # rubocop: disable Style/UnneededSort + VersionSorter.sort(versions).last # rubocop: disable Style/RedundantSort end end end diff --git a/app/presenters/project_presenter.rb b/app/presenters/project_presenter.rb index 86fd405812e..ef75c160b2d 100644 --- a/app/presenters/project_presenter.rb +++ b/app/presenters/project_presenter.rb @@ -7,6 +7,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated include StorageHelper include TreeHelper include IconsHelper + include BlobHelper include ChecksCollaboration include Gitlab::Utils::StrongMemoize @@ -114,7 +115,11 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated end def add_ci_yml_path - add_special_file_path(file_name: '.gitlab-ci.yml') + add_special_file_path(file_name: ci_config_path_or_default) + end + + def add_ci_yml_ide_path + ide_edit_path(project, default_branch_or_master, ci_config_path_or_default) end def add_readme_path @@ -219,7 +224,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated if current_user && can_current_user_push_to_default_branch? AnchorData.new(false, statistic_icon + _('New file'), - project_new_blob_path(project, default_branch || 'master'), + project_new_blob_path(project, default_branch_or_master), 'missing') end end @@ -325,7 +330,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated if cicd_missing? AnchorData.new(false, statistic_icon + _('Set up CI/CD'), - add_ci_yml_path) + add_ci_yml_ide_path) elsif repository.gitlab_ci_yml.present? AnchorData.new(false, statistic_icon('doc-text') + _('CI/CD configuration'), @@ -397,7 +402,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated commit_message ||= s_("CommitMessage|Add %{file_name}") % { file_name: file_name } project_new_blob_path( project, - project.default_branch || 'master', + default_branch_or_master, file_name: file_name, commit_message: commit_message, branch_name: branch_name diff --git a/app/presenters/projects/prometheus/alert_presenter.rb b/app/presenters/projects/prometheus/alert_presenter.rb index 49859f27edd..783b2b2b1e0 100644 --- a/app/presenters/projects/prometheus/alert_presenter.rb +++ b/app/presenters/projects/prometheus/alert_presenter.rb @@ -3,7 +3,6 @@ module Projects module Prometheus class AlertPresenter < Gitlab::View::Presenter::Delegated - RESERVED_ANNOTATIONS = %w(gitlab_incident_markdown gitlab_y_label title).freeze GENERIC_ALERT_SUMMARY_ANNOTATIONS = %w(monitoring_tool service hosts).freeze MARKDOWN_LINE_BREAK = " \n".freeze INCIDENT_LABEL_NAME = ::IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES[:title].freeze @@ -51,22 +50,11 @@ module Projects def issue_summary_markdown <<~MARKDOWN.chomp - #### Summary - #{metadata_list} - #{alert_details}#{metric_embed_for_alert} + #{metric_embed_for_alert} MARKDOWN end - def annotation_list - strong_memoize(:annotation_list) do - annotations - .reject { |annotation| annotation.label.in?(RESERVED_ANNOTATIONS | GENERIC_ALERT_SUMMARY_ANNOTATIONS) } - .map { |annotation| list_item(annotation.label, annotation.value) } - .join(MARKDOWN_LINE_BREAK) - end - end - def metric_embed_for_alert "\n[](#{metrics_dashboard_url})" if metrics_dashboard_url end @@ -111,15 +99,8 @@ module Projects metadata.join(MARKDOWN_LINE_BREAK) end - def alert_details - if annotation_list.present? - <<~MARKDOWN.chomp - - #### Alert Details - - #{annotation_list} - MARKDOWN - end + def details + Gitlab::Utils::InlineHash.merge_keys(payload) end def list_item(key, value) |