Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7982a2ae
Commit
7982a2ae
authored
May 27, 2021
by
Andy Soiron
Committed by
Luke Duncalfe
May 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix slack service with label filter on issue event
parent
d2e6bb87
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
11 deletions
+25
-11
app/models/project_services/chat_notification_service.rb
app/models/project_services/chat_notification_service.rb
+5
-5
spec/models/project_services/chat_notification_service_spec.rb
...models/project_services/chat_notification_service_spec.rb
+20
-6
No files found.
app/models/project_services/chat_notification_service.rb
View file @
7982a2ae
...
...
@@ -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
)
...
...
spec/models/project_services/chat_notification_service_spec.rb
View file @
7982a2ae
...
...
@@ -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
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment