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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
2fec4183
Commit
2fec4183
authored
Jun 14, 2018
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ChatNotificationService - fix sending tag notifications when "only default branch" enabled
parent
fd93d8f0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
17 deletions
+70
-17
app/models/project_services/chat_notification_service.rb
app/models/project_services/chat_notification_service.rb
+1
-0
changelogs/unreleased/45487-slack-tag-push-notifs.yml
changelogs/unreleased/45487-slack-tag-push-notifs.yml
+5
-0
spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb
...xamples/slack_mattermost_notifications_shared_examples.rb
+64
-17
No files found.
app/models/project_services/chat_notification_service.rb
View file @
2fec4183
...
...
@@ -155,6 +155,7 @@ class ChatNotificationService < Service
end
def
notify_for_ref?
(
data
)
return
true
if
data
[
:object_kind
]
==
'tag_push'
return
true
if
data
.
dig
(
:object_attributes
,
:tag
)
return
true
unless
notify_only_default_branch?
...
...
changelogs/unreleased/45487-slack-tag-push-notifs.yml
0 → 100644
View file @
2fec4183
---
title
:
Fix chat service tag notifications not sending when only default branch enabled
merge_request
:
19864
author
:
type
:
fixed
spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb
View file @
2fec4183
...
...
@@ -245,6 +245,70 @@ RSpec.shared_examples 'slack or mattermost notifications' do
end
end
describe
'Push events'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
creator:
user
)
}
before
do
allow
(
chat_service
).
to
receive_messages
(
project:
project
,
service_hook:
true
,
webhook:
webhook_url
)
WebMock
.
stub_request
(
:post
,
webhook_url
)
end
context
'only notify for the default branch'
do
context
'when enabled'
do
before
do
chat_service
.
notify_only_default_branch
=
true
end
it
'does not notify push events if they are not for the default branch'
do
ref
=
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}
test"
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project
,
user
,
nil
,
nil
,
ref
,
[])
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
not_to
have_requested
(
:post
,
webhook_url
)
end
it
'notifies about push events for the default branch'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
user
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
it
'still notifies about pushed tags'
do
ref
=
"
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}
test"
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project
,
user
,
nil
,
nil
,
ref
,
[])
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
context
'when disabled'
do
before
do
chat_service
.
notify_only_default_branch
=
false
end
it
'notifies about all push events'
do
ref
=
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}
test"
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project
,
user
,
nil
,
nil
,
ref
,
[])
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
end
end
describe
"Note events"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
creator:
user
)
}
...
...
@@ -394,23 +458,6 @@ RSpec.shared_examples 'slack or mattermost notifications' do
expect
(
result
).
to
be_falsy
end
it
'does not notify push events if they are not for the default branch'
do
ref
=
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}
test"
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project
,
user
,
nil
,
nil
,
ref
,
[])
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
not_to
have_requested
(
:post
,
webhook_url
)
end
it
'notifies about push events for the default branch'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
user
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
context
'when disabled'
do
...
...
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