diff options
Diffstat (limited to 'app/presenters')
-rw-r--r-- | app/presenters/alert_management/alert_presenter.rb | 33 | ||||
-rw-r--r-- | app/presenters/event_presenter.rb | 22 | ||||
-rw-r--r-- | app/presenters/merge_request_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/project_presenter.rb | 6 | ||||
-rw-r--r-- | app/presenters/projects/prometheus/alert_presenter.rb | 179 | ||||
-rw-r--r-- | app/presenters/sentry_error_presenter.rb | 2 | ||||
-rw-r--r-- | app/presenters/snippet_presenter.rb | 10 |
7 files changed, 59 insertions, 195 deletions
diff --git a/app/presenters/alert_management/alert_presenter.rb b/app/presenters/alert_management/alert_presenter.rb index 5debe6d5dbd..4bfa3dc9a13 100644 --- a/app/presenters/alert_management/alert_presenter.rb +++ b/app/presenters/alert_management/alert_presenter.rb @@ -8,10 +8,11 @@ module AlertManagement MARKDOWN_LINE_BREAK = " \n" HORIZONTAL_LINE = "\n\n---\n\n" + INCIDENT_LABEL_NAME = ::IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES[:title] delegate :metrics_dashboard_url, :runbook, to: :parsed_payload - def initialize(alert, _attributes = {}) + def initialize(alert, **attributes) super @alert = alert @@ -38,6 +39,30 @@ module AlertManagement Gitlab::Utils::InlineHash.merge_keys(payload) end + def show_incident_issues_link? + project.incident_management_setting&.create_issue? + end + + def show_performance_dashboard_link? + prometheus_alert.present? + end + + def incident_issues_link + project_issues_url(project, label_name: INCIDENT_LABEL_NAME) + end + + def performance_dashboard_link + if environment + metrics_project_environment_url(project, environment) + else + metrics_project_environments_url(project) + end + end + + def email_title + [environment&.name, query_title].compact.join(': ') + end + private attr_reader :alert, :project @@ -80,5 +105,11 @@ module AlertManagement def host_links hosts.join(' ') end + + def query_title + return title unless prometheus_alert + + "#{prometheus_alert.title} #{prometheus_alert.computed_operator} #{prometheus_alert.threshold} for 5 minutes" + end end end diff --git a/app/presenters/event_presenter.rb b/app/presenters/event_presenter.rb index 8f2388c2c31..c37721f7213 100644 --- a/app/presenters/event_presenter.rb +++ b/app/presenters/event_presenter.rb @@ -29,4 +29,26 @@ class EventPresenter < Gitlab::View::Presenter::Delegated '' end end + + def target_type_name + if design? + 'Design' + elsif wiki_page? + 'Wiki Page' + elsif target_type.present? + target_type.titleize + else + "Project" + end.downcase + end + + def note_target_type_name + return unless note? + + if design_note? + 'Design' + else + target.noteable_type.titleize + end.downcase + end end diff --git a/app/presenters/merge_request_presenter.rb b/app/presenters/merge_request_presenter.rb index 1ff02412994..a22138011ae 100644 --- a/app/presenters/merge_request_presenter.rb +++ b/app/presenters/merge_request_presenter.rb @@ -37,7 +37,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated end def remove_wip_path - if work_in_progress? && can?(current_user, :update_merge_request, merge_request.project) + if can?(current_user, :update_merge_request, merge_request.project) remove_wip_project_merge_request_path(project, merge_request) end end diff --git a/app/presenters/project_presenter.rb b/app/presenters/project_presenter.rb index ef75c160b2d..0be8a4d5472 100644 --- a/app/presenters/project_presenter.rb +++ b/app/presenters/project_presenter.rb @@ -118,10 +118,6 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated 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 add_special_file_path(file_name: 'README.md') end @@ -330,7 +326,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated if cicd_missing? AnchorData.new(false, statistic_icon + _('Set up CI/CD'), - add_ci_yml_ide_path) + add_ci_yml_path) elsif repository.gitlab_ci_yml.present? AnchorData.new(false, statistic_icon('doc-text') + _('CI/CD configuration'), diff --git a/app/presenters/projects/prometheus/alert_presenter.rb b/app/presenters/projects/prometheus/alert_presenter.rb deleted file mode 100644 index 783b2b2b1e0..00000000000 --- a/app/presenters/projects/prometheus/alert_presenter.rb +++ /dev/null @@ -1,179 +0,0 @@ -# frozen_string_literal: true - -module Projects - module Prometheus - class AlertPresenter < Gitlab::View::Presenter::Delegated - GENERIC_ALERT_SUMMARY_ANNOTATIONS = %w(monitoring_tool service hosts).freeze - MARKDOWN_LINE_BREAK = " \n".freeze - INCIDENT_LABEL_NAME = ::IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES[:title].freeze - METRIC_TIME_WINDOW = 30.minutes - - def full_title - [environment_name, alert_title].compact.join(': ') - end - - def project_full_path - project.full_path - end - - def metric_query - gitlab_alert&.full_query - end - - def environment_name - environment&.name - end - - def performance_dashboard_link - if environment - metrics_project_environment_url(project, environment) - else - metrics_project_environments_url(project) - end - end - - def show_performance_dashboard_link? - gitlab_alert.present? - end - - def show_incident_issues_link? - project.incident_management_setting&.create_issue? - end - - def incident_issues_link - project_issues_url(project, label_name: INCIDENT_LABEL_NAME) - end - - def start_time - starts_at&.strftime('%d %B %Y, %-l:%M%p (%Z)') - end - - def issue_summary_markdown - <<~MARKDOWN.chomp - #{metadata_list} - #{metric_embed_for_alert} - MARKDOWN - end - - def metric_embed_for_alert - "\n[](#{metrics_dashboard_url})" if metrics_dashboard_url - end - - def metrics_dashboard_url - strong_memoize(:metrics_dashboard_url) do - embed_url_for_gitlab_alert || embed_url_for_self_managed_alert - end - end - - def details_url - return unless am_alert - - ::Gitlab::Routing.url_helpers.details_project_alert_management_url( - project, - am_alert.iid - ) - end - - private - - def alert_title - query_title || title - end - - def query_title - return unless gitlab_alert - - "#{gitlab_alert.title} #{gitlab_alert.computed_operator} #{gitlab_alert.threshold} for 5 minutes" - end - - def metadata_list - metadata = [] - - metadata << list_item('Start time', start_time) if start_time - metadata << list_item('full_query', backtick(full_query)) if full_query - metadata << list_item(service.label.humanize, service.value) if service - metadata << list_item(monitoring_tool.label.humanize, monitoring_tool.value) if monitoring_tool - metadata << list_item(hosts.label.humanize, host_links) if hosts - metadata << list_item('GitLab alert', details_url) if details_url - - metadata.join(MARKDOWN_LINE_BREAK) - end - - def details - Gitlab::Utils::InlineHash.merge_keys(payload) - end - - def list_item(key, value) - "**#{key}:** #{value}".strip - end - - def backtick(value) - "`#{value}`" - end - - GENERIC_ALERT_SUMMARY_ANNOTATIONS.each do |annotation_name| - define_method(annotation_name) do - annotations.find { |a| a.label == annotation_name } - end - end - - def host_links - Array(hosts.value).join(' ') - end - - def embed_url_for_gitlab_alert - return unless gitlab_alert - - metrics_dashboard_project_prometheus_alert_url( - project, - gitlab_alert.prometheus_metric_id, - environment_id: environment.id, - embedded: true, - **alert_embed_window_params(embed_time) - ) - end - - def embed_url_for_self_managed_alert - return unless environment && full_query && title - - metrics_dashboard_project_environment_url( - project, - environment, - embed_json: dashboard_for_self_managed_alert.to_json, - embedded: true, - **alert_embed_window_params(embed_time) - ) - end - - def embed_time - starts_at || Time.current - end - - def alert_embed_window_params(time) - { - start: format_embed_timestamp(time - METRIC_TIME_WINDOW), - end: format_embed_timestamp(time + METRIC_TIME_WINDOW) - } - end - - def format_embed_timestamp(time) - time.utc.strftime('%FT%TZ') - end - - def dashboard_for_self_managed_alert - { - panel_groups: [{ - panels: [{ - type: 'area-chart', - title: title, - y_label: y_label, - metrics: [{ - query_range: full_query - }] - }] - }] - } - end - end - end -end diff --git a/app/presenters/sentry_error_presenter.rb b/app/presenters/sentry_error_presenter.rb index ba724b0f8be..669bcb68b7c 100644 --- a/app/presenters/sentry_error_presenter.rb +++ b/app/presenters/sentry_error_presenter.rb @@ -14,7 +14,7 @@ class SentryErrorPresenter < Gitlab::View::Presenter::Delegated end def project_id - Gitlab::GlobalId.build(model_name: 'Project', id: error.project_id).to_s + Gitlab::GlobalId.build(model_name: 'SentryProject', id: error.project_id).to_s end def frequency diff --git a/app/presenters/snippet_presenter.rb b/app/presenters/snippet_presenter.rb index d814c4404b6..695aa266e2c 100644 --- a/app/presenters/snippet_presenter.rb +++ b/app/presenters/snippet_presenter.rb @@ -32,15 +32,9 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated end def blob - blobs.first - end + return snippet.blob if snippet.empty_repo? - def blobs - if snippet.empty_repo? - [snippet.blob] - else - snippet.blobs - end + blobs.first end private |