Commit 4d2caa25 authored by Sean Arnold's avatar Sean Arnold

Update variables and specs

- Update URL helper
parent 786a5a45
...@@ -48,10 +48,9 @@ module AlertManagement ...@@ -48,10 +48,9 @@ module AlertManagement
private private
def details_url def details_url
::Gitlab::Routing.url_helpers.details_namespace_project_alert_management_url( ::Gitlab::Routing.url_helpers.details_project_alert_management_url(
id: alert, project,
project_id: project, alert.iid
namespace_id: project.namespace
) )
end end
......
...@@ -78,12 +78,11 @@ module Projects ...@@ -78,12 +78,11 @@ module Projects
end end
def details_url def details_url
return unless alert return unless am_alert
::Gitlab::Routing.url_helpers.details_namespace_project_alert_management_url( ::Gitlab::Routing.url_helpers.details_project_alert_management_url(
id: alert, project,
project_id: project, am_alert.iid
namespace_id: project.namespace
) )
end end
......
...@@ -14,7 +14,7 @@ module IncidentManagement ...@@ -14,7 +14,7 @@ module IncidentManagement
def execute def execute
return error('setting disabled') unless incident_management_setting.create_issue? return error('setting disabled') unless incident_management_setting.create_issue?
return error('invalid alert') unless presented_alert.valid? return error('invalid alert') unless alert_presenter.valid?
result = create_incident result = create_incident
return error(result.message, result.payload[:issue]) unless result.success? return error(result.message, result.payload[:issue]) unless result.success?
...@@ -34,7 +34,7 @@ module IncidentManagement ...@@ -34,7 +34,7 @@ module IncidentManagement
end end
def issue_title def issue_title
presented_alert.full_title alert_presenter.full_title
end end
def issue_description def issue_description
...@@ -48,15 +48,15 @@ module IncidentManagement ...@@ -48,15 +48,15 @@ module IncidentManagement
end end
def alert_summary def alert_summary
presented_alert.issue_summary_markdown alert_presenter.issue_summary_markdown
end end
def alert_markdown def alert_markdown
presented_alert.alert_markdown alert_presenter.alert_markdown
end end
def presented_alert def alert_presenter
strong_memoize(:presented_alert) do strong_memoize(:alert_presenter) do
Gitlab::Alerting::Alert.for_alert_management_alert(project: project, alert: alert).present Gitlab::Alerting::Alert.for_alert_management_alert(project: project, alert: alert).present
end end
end end
......
...@@ -7,7 +7,7 @@ module Gitlab ...@@ -7,7 +7,7 @@ module Gitlab
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
include Presentable include Presentable
attr_accessor :project, :payload, :alert attr_accessor :project, :payload, :am_alert
def self.for_alert_management_alert(project:, alert:) def self.for_alert_management_alert(project:, alert:)
params = if alert.prometheus? params = if alert.prometheus?
...@@ -16,7 +16,7 @@ module Gitlab ...@@ -16,7 +16,7 @@ module Gitlab
Gitlab::Alerting::NotificationPayloadParser.call(alert.payload.to_h, alert.project) Gitlab::Alerting::NotificationPayloadParser.call(alert.payload.to_h, alert.project)
end end
self.new(project: project, payload: params, alert: alert) self.new(project: project, payload: params, am_alert: alert)
end end
def gitlab_alert def gitlab_alert
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe AlertManagement::AlertPresenter do RSpec.describe AlertManagement::AlertPresenter do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:generic_payload) do let_it_be(:generic_payload) do
{ {
'title' => 'Alert title', 'title' => 'Alert title',
'start_time' => '2020-04-27T10:10:22.265949279Z', 'start_time' => '2020-04-27T10:10:22.265949279Z',
...@@ -18,7 +18,7 @@ RSpec.describe AlertManagement::AlertPresenter do ...@@ -18,7 +18,7 @@ RSpec.describe AlertManagement::AlertPresenter do
build(:alert_management_alert, :with_description, :with_host, :with_service, :with_monitoring_tool, project: project, payload: generic_payload) build(:alert_management_alert, :with_description, :with_host, :with_service, :with_monitoring_tool, project: project, payload: generic_payload)
end end
let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.id}/details" } let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.iid}/details" }
subject(:presenter) { described_class.new(alert) } subject(:presenter) { described_class.new(alert) }
......
...@@ -20,7 +20,7 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do ...@@ -20,7 +20,7 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do
create(:alert_management_alert, :prometheus, project: project, payload: payload) create(:alert_management_alert, :prometheus, project: project, payload: payload)
end end
let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.id}/details" } let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.iid}/details" }
subject(:presenter) { described_class.new(alert) } subject(:presenter) { described_class.new(alert) }
......
...@@ -300,9 +300,9 @@ RSpec.describe Projects::Prometheus::AlertPresenter do ...@@ -300,9 +300,9 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
context 'alert management alert present' do context 'alert management alert present' do
let_it_be(:am_alert) { create(:alert_management_alert, project: project) } let_it_be(:am_alert) { create(:alert_management_alert, project: project) }
let(:alert) { create(:alerting_alert, project: project, payload: payload, alert: am_alert) } let(:alert) { create(:alerting_alert, project: project, payload: payload, am_alert: am_alert) }
it { is_expected.to eq("http://localhost/#{project.full_path}/-/alert_management/#{am_alert.id}/details") } it { is_expected.to eq("http://localhost/#{project.full_path}/-/alert_management/#{am_alert.iid}/details") }
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment