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
Tatuya Kamada
gitlab-ce
Commits
091c2608
Commit
091c2608
authored
Mar 23, 2017
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve readability and add test
parent
fed319b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
10 deletions
+27
-10
app/models/project_services/chat_notification_service.rb
app/models/project_services/chat_notification_service.rb
+7
-10
spec/features/admin/admin_settings_spec.rb
spec/features/admin/admin_settings_spec.rb
+1
-0
spec/support/slack_mattermost_notifications_shared_examples.rb
...support/slack_mattermost_notifications_shared_examples.rb
+19
-0
No files found.
app/models/project_services/chat_notification_service.rb
View file @
091c2608
...
@@ -17,7 +17,7 @@ class ChatNotificationService < Service
...
@@ -17,7 +17,7 @@ class ChatNotificationService < Service
if
properties
.
nil?
if
properties
.
nil?
self
.
properties
=
{}
self
.
properties
=
{}
self
.
notify_only_broken_pipelines
=
true
self
.
notify_only_broken_pipelines
=
true
self
.
notify_only_default_branch
=
fals
e
self
.
notify_only_default_branch
=
tru
e
end
end
end
end
...
@@ -137,20 +137,17 @@ class ChatNotificationService < Service
...
@@ -137,20 +137,17 @@ class ChatNotificationService < Service
end
end
def
should_pipeline_be_notified?
(
data
)
def
should_pipeline_be_notified?
(
data
)
notify_for_
branch
(
data
)
&&
notify_for_pipeline
(
data
)
notify_for_
ref?
(
data
)
&&
notify_for_pipeline?
(
data
)
end
end
def
notify_for_branch
(
data
)
def
notify_for_ref?
(
data
)
ref_type
=
data
[
:object_attributes
][
:tag
]
?
'tag'
:
'branch'
return
true
if
data
[
:object_attributes
][
:tag
]
return
true
unless
notify_only_default_branch
if
ref_type
==
'branch'
&&
notify_only_default_branch
data
[
:object_attributes
][
:ref
]
==
project
.
default_branch
data
[
:object_attributes
][
:ref
]
==
project
.
default_branch
else
true
end
end
end
def
notify_for_pipeline
(
data
)
def
notify_for_pipeline
?
(
data
)
case
data
[
:object_attributes
][
:status
]
case
data
[
:object_attributes
][
:status
]
when
'success'
when
'success'
!
notify_only_broken_pipelines?
!
notify_only_broken_pipelines?
...
...
spec/features/admin/admin_settings_spec.rb
View file @
091c2608
...
@@ -34,6 +34,7 @@ feature 'Admin updates settings', feature: true do
...
@@ -34,6 +34,7 @@ feature 'Admin updates settings', feature: true do
fill_in
'Username'
,
with:
'test_user'
fill_in
'Username'
,
with:
'test_user'
fill_in
'service_push_channel'
,
with:
'#test_channel'
fill_in
'service_push_channel'
,
with:
'#test_channel'
page
.
check
(
'Notify only broken pipelines'
)
page
.
check
(
'Notify only broken pipelines'
)
page
.
check
(
'Notify only default branch'
)
check_all_events
check_all_events
click_on
'Save'
click_on
'Save'
...
...
spec/support/slack_mattermost_notifications_shared_examples.rb
View file @
091c2608
...
@@ -324,5 +324,24 @@ RSpec.shared_examples 'slack or mattermost notifications' do
...
@@ -324,5 +324,24 @@ RSpec.shared_examples 'slack or mattermost notifications' do
it_behaves_like
'call Slack/Mattermost API'
it_behaves_like
'call Slack/Mattermost API'
end
end
end
end
context
'only notify for the default branch'
do
context
'when enabled'
do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
status:
'failed'
,
ref:
'not-the-default-branch'
)
end
before
do
chat_service
.
notify_only_default_branch
=
true
end
it
'does not call the Slack/Mattermost API for pipeline events'
do
data
=
Gitlab
::
DataBuilder
::
Pipeline
.
build
(
pipeline
)
result
=
chat_service
.
execute
(
data
)
expect
(
result
).
to
be_falsy
end
end
end
end
end
end
end
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