Commit 4d7dbe7e authored by Vitali Tatarintev's avatar Vitali Tatarintev

Create add_severity_system_note feature flag

Hide adding a severity system note behind feature flag
parent 0deaeb61
......@@ -10,6 +10,8 @@ module SystemNotes
#
# Returns the created Note object
def change_incident_severity
return unless Feature.enabled?(:add_severity_system_note, noteable.project)
severity = noteable.severity
if severity_label = IssuableSeverity::SEVERITY_LABELS[severity.to_sym]
......
---
name: add_severity_system_note
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/42358
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/251110
group: group::health
type: development
default_enabled: false
......@@ -11,45 +11,68 @@ RSpec.describe ::SystemNotes::IncidentService do
describe '#change_incident_severity' do
subject(:change_severity) { described_class.new(noteable: noteable, project: project, author: author).change_incident_severity }
it_behaves_like 'a system note' do
let(:action) { 'severity' }
before do
allow(Gitlab::AppLogger).to receive(:error).and_call_original
end
IssuableSeverity.severities.keys.each do |severity|
context "with #{severity} severity" do
context 'with add_severity_system_note feature flag enabled' do
before do
stub_feature_flags(add_severity_system_note: project)
end
it_behaves_like 'a system note' do
let(:action) { 'severity' }
end
IssuableSeverity.severities.keys.each do |severity|
context "with #{severity} severity" do
before do
issuable_severity.update!(severity: severity)
end
it 'has the appropriate message' do
severity_label = IssuableSeverity::SEVERITY_LABELS.fetch(severity.to_sym)
expect(change_severity.note).to eq("changed the severity to **#{severity_label}**")
end
end
end
context 'when severity is invalid' do
let(:invalid_severity) { 'invalid-severity' }
before do
issuable_severity.update!(severity: severity)
allow(noteable).to receive(:severity).and_return(invalid_severity)
end
it 'has the appropriate message' do
severity_label = IssuableSeverity::SEVERITY_LABELS.fetch(severity.to_sym)
it 'does not create system note' do
expect { change_severity }.not_to change { noteable.notes.count }
end
expect(change_severity.note).to eq("changed the severity to **#{severity_label}**")
it 'writes error to logs' do
change_severity
expect(Gitlab::AppLogger).to have_received(:error).with(
message: 'Cannot create a system note for severity change',
noteable_class: noteable.class.to_s,
noteable_id: noteable.id,
severity: invalid_severity
)
end
end
end
context 'when severity is invalid' do
let(:invalid_severity) { 'invalid-severity' }
context 'with add_severity_system_note feature flag disabled' do
before do
allow(noteable).to receive(:severity).and_return(invalid_severity)
allow(Gitlab::AppLogger).to receive(:error).and_call_original
stub_feature_flags(add_severity_system_note: false)
end
it 'does not create system note' do
expect { change_severity }.not_to change { noteable.notes.count }
end
it 'writes error to logs' do
change_severity
expect(Gitlab::AppLogger).to have_received(:error).with(
message: 'Cannot create a system note for severity change',
noteable_class: noteable.class.to_s,
noteable_id: noteable.id,
severity: invalid_severity
)
it 'does not write error to logs' do
expect(Gitlab::AppLogger).not_to have_received(:error)
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