Commit 40332d0e authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'pl-incident-issue-service-alert_bot' into 'master'

Pass alert bot user when creating incidents

See merge request gitlab-org/gitlab-ee!14860
parents 84d34b7d ef3ad788
......@@ -13,6 +13,10 @@ module IncidentManagement
DESCRIPTION
}.freeze
def initialize(project, params)
super(project, User.alert_bot, params)
end
def execute
return error_with('setting disabled') unless incident_management_setting.create_issue?
return error_with('invalid alert') unless alert.valid?
......@@ -42,19 +46,13 @@ module IncidentManagement
def do_create_issue(**params)
Issues::CreateService.new(
project,
issue_author,
current_user,
title: issue_title,
description: issue_description,
**params
).execute
end
def issue_author
strong_memoize(:issue_author) do
User.alert_bot
end
end
def issue_title
alert.full_title
end
......@@ -77,7 +75,7 @@ module IncidentManagement
def find_or_create_label(**params)
Labels::FindOrCreateService
.new(issue_author, project, **params)
.new(current_user, project, **params)
.execute
end
......
......@@ -21,7 +21,7 @@ module IncidentManagement
def create_issue(project, alert)
IncidentManagement::CreateIssueService
.new(project, nil, alert)
.new(project, alert)
.execute
end
end
......
......@@ -4,7 +4,8 @@ require 'spec_helper'
describe IncidentManagement::CreateIssueService do
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_title) { 'TITLE' }
let(:alert_annotations) { { title: alert_title } }
......@@ -38,7 +39,7 @@ describe IncidentManagement::CreateIssueService do
it 'creates an issue with alert summary only' do
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.description).to include(alert_presenter.issue_summary_markdown)
expect(separator_count(issue.description)).to eq 0
......@@ -164,7 +165,7 @@ describe IncidentManagement::CreateIssueService do
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 include(gitlab_alert.environment.name)
expect(issue.title).to include(query_title)
......
......@@ -15,7 +15,7 @@ describe IncidentManagement::ProcessAlertWorker do
expect(Project).to receive(:find_by_id).and_call_original
expect(IncidentManagement::CreateIssueService)
.to receive(:new).with(project, nil, :alert)
.to receive(:new).with(project, :alert)
.and_return(create_issue_service)
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