Commit 6601de8d authored by Sean McGivern's avatar Sean McGivern

Merge branch 'issue_12952' into 'master'

Do not show 'automatically removed' for manually removed labels

Closes #12952

See merge request gitlab-org/gitlab-ee!16079
parents 4d0875c0 bc117d42
......@@ -9,16 +9,34 @@ module EE
override :removed_prefix
def removed_prefix
scoped_labels_event? ? 'automatically removed' : super
if any_label_manually_removed?
super
else
'automatically removed'
end
end
override :added_suffix
def added_suffix
scoped_labels_event? ? 'scoped' : super
scoped_labels_event? ? 'scoped' : super
end
def scoped_labels_event?
events.first.label&.scoped_label?
end
# Returns true if a scoped label "remove" event doesn't have a matching "add" event.
def any_label_manually_removed?
return true unless scoped_labels_event?
remove_events = events.select(&:remove?)
add_events = events.select(&:add?)
remove_events.any? do |remove_event|
add_events.none? do |add_event|
add_event.label.scoped_label_key == remove_event.label.scoped_label_key
end
end
end
end
end
---
title: Do not show 'automatically removed' suffix for manually removed labels
merge_request: 16079
author:
type: fixed
......@@ -10,12 +10,6 @@ describe ResourceEvents::MergeIntoNotesService do
create(:resource_label_event, event_params.merge(params))
end
def create_note(params)
opts = { noteable: resource, project: project }
create(:note_on_issue, opts.merge(params))
end
set(:project) { create(:project) }
set(:user) { create(:user) }
set(:resource) { create(:issue, project: project) }
......@@ -58,5 +52,38 @@ describe ResourceEvents::MergeIntoNotesService do
expect(notes.count).to eq(4)
expect(notes.map(&:note)).to match_array(expected)
end
context 'scoped labels' do
context 'when all labels are automatically removed' do
it 'adds "automatically removed" message' do
create_event(created_at: time, label: scoped_label_group1_1, action: :add)
create_event(created_at: time, label: scoped_label_group1_2, action: :remove)
create_event(created_at: time, label: scoped_label_group2_1, action: :add)
create_event(created_at: time, label: scoped_label_group2_2, action: :remove)
note = described_class.new(resource, user).execute.first.note
added_scoped_labels_refs = [scoped_label_group1_1, scoped_label_group2_1].map(&:to_reference).sort.join(' ')
removed_scoped_labels_refs = [scoped_label_group1_2, scoped_label_group2_2].map(&:to_reference).sort.join(' ')
expect(note).to eq("added #{added_scoped_labels_refs} scoped labels and automatically removed #{removed_scoped_labels_refs} labels")
end
end
context 'when any of the labels is manually removed' do
it 'adds "removed" message' do
create_event(created_at: time, label: scoped_label_group1_1, action: :add)
create_event(created_at: time, label: scoped_label_group1_2, action: :remove)
create_event(created_at: time, label: scoped_label_group2_1, action: :remove)
note = described_class.new(resource, user).execute.first.note
added_scoped_labels_refs = scoped_label_group1_1.to_reference
removed_scoped_labels_refs = [scoped_label_group1_2, scoped_label_group2_1].map(&:to_reference).sort.join(' ')
expect(note).to eq("added #{added_scoped_labels_refs} scoped label and removed #{removed_scoped_labels_refs} labels")
end
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