diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-13 12:10:03 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-13 12:10:03 +0000 |
commit | 75ee59f7a108cf0c57e1e66e3ef5e439bae24fcd (patch) | |
tree | b2f1ec89e16c6b27041f608c9fb12b7586e5ce94 /lib | |
parent | e79918ce90dc31527be1ef0140a99cfe450d931e (diff) | |
download | gitlab-ce-75ee59f7a108cf0c57e1e66e3ef5e439bae24fcd.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/metrics/dashboard/stages/alerts_inserter.rb | 41 | ||||
-rw-r--r-- | lib/gitlab/static_site_editor/config.rb | 36 |
2 files changed, 77 insertions, 0 deletions
diff --git a/lib/gitlab/metrics/dashboard/stages/alerts_inserter.rb b/lib/gitlab/metrics/dashboard/stages/alerts_inserter.rb new file mode 100644 index 00000000000..38736158c3b --- /dev/null +++ b/lib/gitlab/metrics/dashboard/stages/alerts_inserter.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'set' + +module Gitlab + module Metrics + module Dashboard + module Stages + class AlertsInserter < BaseStage + include ::Gitlab::Utils::StrongMemoize + + def transform! + return if metrics_with_alerts.empty? + + for_metrics do |metric| + next unless metrics_with_alerts.include?(metric[:metric_id]) + + metric[:alert_path] = alert_path(metric[:metric_id], project, params[:environment]) + end + end + + private + + def metrics_with_alerts + strong_memoize(:metrics_with_alerts) do + alerts = ::Projects::Prometheus::AlertsFinder + .new(project: project, environment: params[:environment]) + .execute + + Set.new(alerts.map(&:prometheus_metric_id)) + end + end + + def alert_path(metric_id, project, environment) + ::Gitlab::Routing.url_helpers.project_prometheus_alert_path(project, metric_id, environment_id: environment.id, format: :json) + end + end + end + end + end +end diff --git a/lib/gitlab/static_site_editor/config.rb b/lib/gitlab/static_site_editor/config.rb new file mode 100644 index 00000000000..4bc0fc95abd --- /dev/null +++ b/lib/gitlab/static_site_editor/config.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Gitlab + module StaticSiteEditor + class Config + def initialize(repository, ref, file_path, return_url) + @repository = repository + @ref = ref + @file_path = file_path + @return_url = return_url + end + + def payload + { + branch: ref, + path: file_path, + commit: commit.id, + project_id: project.id, + project: project.path, + namespace: project.namespace.path, + return_url: return_url + } + end + + private + + attr_reader :repository, :ref, :file_path, :return_url + + delegate :project, to: :repository + + def commit + repository.commit(ref) + end + end + end +end |