Commit 7982a2ae authored by Andy Soiron's avatar Andy Soiron Committed by Luke Duncalfe

Fix slack service with label filter on issue event

parent d2e6bb87
......@@ -92,14 +92,14 @@ class ChatNotificationService < Integration
def execute(data)
return unless supported_events.include?(data[:object_kind])
return unless notify_label?(data)
return unless webhook.present?
object_kind = data[:object_kind]
data = custom_data(data)
return unless notify_label?(data)
# WebHook events often have an 'update' event that follows a 'open' or
# 'close' action. Ignore update events for now to prevent duplicate
# messages from arriving.
......@@ -156,9 +156,9 @@ class ChatNotificationService < Integration
def notify_label?(data)
return true unless SUPPORTED_EVENTS_FOR_LABEL_FILTER.include?(data[:object_kind]) && labels_to_be_notified.present?
labels = data.dig(:issue, :labels) || data.dig(:merge_request, :labels)
labels = data[:labels] || data.dig(:issue, :labels) || data.dig(:merge_request, :labels) || data.dig(:object_attributes, :labels)
return false if labels.nil?
return false if labels.blank?
matching_labels = labels_to_be_notified_list & labels.pluck(:title)
......@@ -179,7 +179,7 @@ class ChatNotificationService < Integration
end
def custom_data(data)
data.merge(project_url: project_url, project_name: project_name)
data.merge(project_url: project_url, project_name: project_name).with_indifferent_access
end
def get_message(object_kind, data)
......
......@@ -89,12 +89,6 @@ RSpec.describe ChatNotificationService do
let(:data) { Gitlab::DataBuilder::Note.build(note, user) }
it 'notifies the chat service' do
expect(chat_service).to receive(:notify).with(any_args)
chat_service.execute(data)
end
shared_examples 'notifies the chat service' do
specify do
expect(chat_service).to receive(:notify).with(any_args)
......@@ -111,6 +105,26 @@ RSpec.describe ChatNotificationService do
end
end
it_behaves_like 'notifies the chat service'
context 'with label filter' do
subject(:chat_service) { described_class.new(labels_to_be_notified: '~Bug') }
it_behaves_like 'notifies the chat service'
context 'MergeRequest events' do
let(:data) { create(:merge_request, labels: [label]).to_hook_data(user) }
it_behaves_like 'notifies the chat service'
end
context 'Issue events' do
let(:data) { issue.to_hook_data(user) }
it_behaves_like 'notifies the chat service'
end
end
context 'when labels_to_be_notified_behavior is not defined' do
subject(:chat_service) { described_class.new(labels_to_be_notified: label_filter) }
......
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