Commit ef3ad788 authored by Peter Leitzen's avatar Peter Leitzen Committed by Rémy Coutable

Pass alert bot user when creaeting incidents

Previously, we passed `nil` as `current_user` to
`IncidentManagement::CreateIssueService.new` and used `issue_author`.

After this commit we pass `User.alert_bot` explicitly and utilize
`current_user` in the service as usual.
parent 84d34b7d
...@@ -13,6 +13,10 @@ module IncidentManagement ...@@ -13,6 +13,10 @@ module IncidentManagement
DESCRIPTION DESCRIPTION
}.freeze }.freeze
def initialize(project, params)
super(project, User.alert_bot, params)
end
def execute def execute
return error_with('setting disabled') unless incident_management_setting.create_issue? return error_with('setting disabled') unless incident_management_setting.create_issue?
return error_with('invalid alert') unless alert.valid? return error_with('invalid alert') unless alert.valid?
...@@ -42,19 +46,13 @@ module IncidentManagement ...@@ -42,19 +46,13 @@ module IncidentManagement
def do_create_issue(**params) def do_create_issue(**params)
Issues::CreateService.new( Issues::CreateService.new(
project, project,
issue_author, current_user,
title: issue_title, title: issue_title,
description: issue_description, description: issue_description,
**params **params
).execute ).execute
end end
def issue_author
strong_memoize(:issue_author) do
User.alert_bot
end
end
def issue_title def issue_title
alert.full_title alert.full_title
end end
...@@ -77,7 +75,7 @@ module IncidentManagement ...@@ -77,7 +75,7 @@ module IncidentManagement
def find_or_create_label(**params) def find_or_create_label(**params)
Labels::FindOrCreateService Labels::FindOrCreateService
.new(issue_author, project, **params) .new(current_user, project, **params)
.execute .execute
end end
......
...@@ -21,7 +21,7 @@ module IncidentManagement ...@@ -21,7 +21,7 @@ module IncidentManagement
def create_issue(project, alert) def create_issue(project, alert)
IncidentManagement::CreateIssueService IncidentManagement::CreateIssueService
.new(project, nil, alert) .new(project, alert)
.execute .execute
end end
end end
......
...@@ -4,7 +4,8 @@ require 'spec_helper' ...@@ -4,7 +4,8 @@ require 'spec_helper'
describe IncidentManagement::CreateIssueService do describe IncidentManagement::CreateIssueService do
let(:project) { create(:project, :repository, :private) } let(:project) { create(:project, :repository, :private) }
let(:service) { described_class.new(project, nil, alert_payload) } let(:user) { User.alert_bot }
let(:service) { described_class.new(project, alert_payload) }
let(:alert_starts_at) { Time.now } let(:alert_starts_at) { Time.now }
let(:alert_title) { 'TITLE' } let(:alert_title) { 'TITLE' }
let(:alert_annotations) { { title: alert_title } } let(:alert_annotations) { { title: alert_title } }
...@@ -38,7 +39,7 @@ describe IncidentManagement::CreateIssueService do ...@@ -38,7 +39,7 @@ describe IncidentManagement::CreateIssueService do
it 'creates an issue with alert summary only' do it 'creates an issue with alert summary only' do
expect(subject).to include(status: :success) expect(subject).to include(status: :success)
expect(issue.author).to eq(User.alert_bot) expect(issue.author).to eq(user)
expect(issue.title).to eq(alert_title) expect(issue.title).to eq(alert_title)
expect(issue.description).to include(alert_presenter.issue_summary_markdown) expect(issue.description).to include(alert_presenter.issue_summary_markdown)
expect(separator_count(issue.description)).to eq 0 expect(separator_count(issue.description)).to eq 0
...@@ -164,7 +165,7 @@ describe IncidentManagement::CreateIssueService do ...@@ -164,7 +165,7 @@ describe IncidentManagement::CreateIssueService do
expect(subject).to include(status: :success) expect(subject).to include(status: :success)
expect(issue.author).to eq(User.alert_bot) expect(issue.author).to eq(user)
expect(issue.title).to eq(alert_presenter.full_title) expect(issue.title).to eq(alert_presenter.full_title)
expect(issue.title).to include(gitlab_alert.environment.name) expect(issue.title).to include(gitlab_alert.environment.name)
expect(issue.title).to include(query_title) expect(issue.title).to include(query_title)
......
...@@ -15,7 +15,7 @@ describe IncidentManagement::ProcessAlertWorker do ...@@ -15,7 +15,7 @@ describe IncidentManagement::ProcessAlertWorker do
expect(Project).to receive(:find_by_id).and_call_original expect(Project).to receive(:find_by_id).and_call_original
expect(IncidentManagement::CreateIssueService) expect(IncidentManagement::CreateIssueService)
.to receive(:new).with(project, nil, :alert) .to receive(:new).with(project, :alert)
.and_return(create_issue_service) .and_return(create_issue_service)
expect(create_issue_service).to receive(:execute) expect(create_issue_service).to receive(:execute)
......
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