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
5c99ba03
Commit
5c99ba03
authored
Sep 01, 2019
by
Balasankar "Balu" C
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify specs to match backend code
Signed-off-by:
Balasankar "Balu" C
<
balasankar@gitlab.com
>
parent
2a86722a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
876 additions
and
77 deletions
+876
-77
spec/features/admin/admin_settings_spec.rb
spec/features/admin/admin_settings_spec.rb
+1
-1
spec/models/project_services/microsoft_teams_service_spec.rb
spec/models/project_services/microsoft_teams_service_spec.rb
+121
-10
spec/models/project_services/pipelines_email_service_spec.rb
spec/models/project_services/pipelines_email_service_spec.rb
+219
-28
spec/support/shared_examples/models/chat_service_shared_examples.rb
...rt/shared_examples/models/chat_service_shared_examples.rb
+195
-12
spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb
...xamples/slack_mattermost_notifications_shared_examples.rb
+340
-26
No files found.
spec/features/admin/admin_settings_spec.rb
View file @
5c99ba03
...
...
@@ -216,7 +216,7 @@ describe 'Admin updates settings' do
fill_in
'Username'
,
with:
'test_user'
fill_in
'service_push_channel'
,
with:
'#test_channel'
page
.
check
(
'Notify only broken pipelines'
)
page
.
check
(
'Notify only default branch'
)
page
.
select
'All branches'
,
from:
'Branches to be notified'
check_all_events
click_on
'Save'
...
...
spec/models/project_services/microsoft_teams_service_spec.rb
View file @
5c99ba03
...
...
@@ -272,14 +272,61 @@ describe MicrosoftTeamsService do
end
end
context
'with default branch'
do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
status:
'failed'
,
sha:
project
.
commit
.
sha
,
ref:
project
.
default_branch
)
end
context
'only notify for the default branch'
do
context
'when enabled'
do
before
do
chat_service
.
branches_to_be_notified
=
"default"
end
it_behaves_like
'call Microsoft Teams API'
end
context
'notify for only protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"protected"
end
it
'does not call the Microsoft Teams API for pipeline events'
do
data
=
Gitlab
::
DataBuilder
::
Pipeline
.
build
(
pipeline
)
result
=
chat_service
.
execute
(
data
)
expect
(
result
).
to
be_falsy
end
end
context
'notify for only default and protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
'call Microsoft Teams API'
end
context
'notify for all branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"all"
end
it_behaves_like
'call Microsoft Teams API'
end
end
context
'with protected branch'
do
before
do
create
(
:protected_branch
,
project:
project
,
name:
'a-protected-branch'
)
end
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
status:
'failed'
,
ref:
'not-the-default
-branch'
)
create
(
:ci_pipeline
,
project:
project
,
status:
'failed'
,
sha:
project
.
commit
.
sha
,
ref:
'a-protected
-branch'
)
end
context
'only notify for the default branch'
do
before
do
chat_service
.
notify_only_default_branch
=
true
chat_service
.
branches_to_be_notified
=
"default"
end
it
'does not call the Microsoft Teams API for pipeline events'
do
...
...
@@ -290,14 +337,78 @@ describe MicrosoftTeamsService do
end
end
context
'when disabled'
do
context
'notify for only protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"protected"
end
it_behaves_like
'call Microsoft Teams API'
end
context
'notify for only default and protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
'call Microsoft Teams API'
end
context
'notify for all branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"all"
end
it_behaves_like
'call Microsoft Teams API'
end
end
context
'with neither protected nor default branch'
do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
:failed
,
project:
project
,
sha:
project
.
commit
.
sha
,
ref:
'not-the-default-branch'
)
create
(
:ci_pipeline
,
project:
project
,
status:
'failed'
,
sha:
project
.
commit
.
sha
,
ref:
'a-random-branch'
)
end
context
'only notify for the default branch'
do
before
do
chat_service
.
branches_to_be_notified
=
"default"
end
it
'does not call the Microsoft Teams API for pipeline events'
do
data
=
Gitlab
::
DataBuilder
::
Pipeline
.
build
(
pipeline
)
result
=
chat_service
.
execute
(
data
)
expect
(
result
).
to
be_falsy
end
end
context
'notify for only protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"protected"
end
it
'does not call the Microsoft Teams API for pipeline events'
do
data
=
Gitlab
::
DataBuilder
::
Pipeline
.
build
(
pipeline
)
result
=
chat_service
.
execute
(
data
)
expect
(
result
).
to
be_falsy
end
end
context
'notify for only default and protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"default_and_protected"
end
it
'does not call the Microsoft Teams API for pipeline events'
do
data
=
Gitlab
::
DataBuilder
::
Pipeline
.
build
(
pipeline
)
result
=
chat_service
.
execute
(
data
)
expect
(
result
).
to
be_falsy
end
end
context
'notify for all branches'
do
before
do
chat_service
.
notify_only_default_branch
=
false
chat_service
.
branches_to_be_notified
=
"all"
end
it_behaves_like
'call Microsoft Teams API'
...
...
spec/models/project_services/pipelines_email_service_spec.rb
View file @
5c99ba03
...
...
@@ -101,27 +101,132 @@ describe PipelinesEmailService, :mailer do
it_behaves_like
'sending email'
end
context
'when pipeline is failed and on a non-default branch'
do
context
'when the pipeline failed'
do
context
'on default branch'
do
before
do
data
[
:object_attributes
][
:ref
]
=
'not-the-default-branch'
pipeline
.
update
(
ref:
'not-the-default-branch'
)
data
[
:object_attributes
][
:ref
]
=
project
.
default_branch
pipeline
.
update
(
ref:
project
.
default_branch
)
end
context
'with notify_only_default branch on
'
do
context
'notifications are enabled only for default branch
'
do
before
do
subject
.
notify_only_default_branch
=
true
subject
.
branches_to_be_notified
=
"default"
end
it_behaves_like
'sending email'
end
context
'with notify_only_default_branch off'
do
context
'notifications are enabled only for protected branch'
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for default and protected branches '
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for all branches'
do
before
do
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
'sending email'
end
end
context
'on a protected branch'
do
before
do
create
(
:protected_branch
,
project:
project
,
name:
'a-protected-branch'
)
data
[
:object_attributes
][
:ref
]
=
'a-protected-branch'
pipeline
.
update
(
ref:
'a-protected-branch'
)
end
context
'notifications are enabled only for default branch'
do
before
do
subject
.
branches_to_be_notified
=
"default"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for protected branch'
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for default and protected branches '
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for all branches'
do
before
do
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
'sending email'
end
end
context
'on a neither protected nor default branch'
do
before
do
data
[
:object_attributes
][
:ref
]
=
'a-random-branch'
pipeline
.
update
(
ref:
'a-random-branch'
)
end
context
'notifications are enabled only for default branch'
do
before
do
subject
.
branches_to_be_notified
=
"default"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for protected branch'
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for default and protected branches '
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for all branches'
do
before
do
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
'sending email'
end
end
end
end
describe
'#execute'
do
before
do
subject
.
project
=
project
end
def
run
subject
.
execute
(
data
)
end
...
...
@@ -159,38 +264,124 @@ describe PipelinesEmailService, :mailer do
end
end
context
'with notify_only_default_branch off'
do
context
'with default branch'
do
context
'when the pipeline failed'
do
context
'on a default branch'
do
before
do
data
[
:object_attributes
][
:ref
]
=
project
.
default_branch
pipeline
.
update
(
ref:
project
.
default_branch
)
end
context
'notifications are enabled only for default branch'
do
before
do
subject
.
branches_to_be_notified
=
"default"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for protected branch'
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it_behaves_like
'not sending email'
end
context
'notifications are enabled only for default and protected branches '
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
'sending email'
end
context
'with non default branch'
do
context
'notifications are enabled only for all branches'
do
before
do
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
'sending email'
end
end
context
'on a protected branch'
do
before
do
create
(
:protected_branch
,
project:
project
,
name:
'a-protected-branch'
)
data
[
:object_attributes
][
:ref
]
=
'a-protected-branch'
pipeline
.
update
(
ref:
'a-protected-branch'
)
end
context
'notifications are enabled only for default branch'
do
before
do
data
[
:object_attributes
][
:ref
]
=
'not-the-default-branch'
pipeline
.
update
(
ref:
'not-the-default-branch'
)
subject
.
branches_to_be_notified
=
"default"
end
it_behaves_like
'not sending email'
end
context
'notifications are enabled only for protected branch'
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it_behaves_like
'sending email'
end
context
'notifications are enabled only for default and protected branches '
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
context
'with notify_only_default_branch on'
do
it_behaves_like
'sending email'
end
context
'notifications are enabled only for all branches'
do
before
do
subject
.
notify_only_default_branch
=
true
subject
.
branches_to_be_notified
=
"all"
end
context
'with default branch'
do
it_behaves_like
'sending email'
end
end
context
'on a neither protected nor default branch'
do
before
do
data
[
:object_attributes
][
:ref
]
=
'a-random-branch'
pipeline
.
update
(
ref:
'a-random-branch'
)
end
context
'notifications are enabled only for default branch'
do
before
do
subject
.
branches_to_be_notified
=
"default"
end
context
'with non default branch'
do
it_behaves_like
'not sending email'
end
context
'notifications are enabled only for protected branch'
do
before
do
data
[
:object_attributes
][
:ref
]
=
'not-the-default-branch'
pipeline
.
update
(
ref:
'not-the-default-branch'
)
subject
.
branches_to_be_notified
=
"protected"
end
it_behaves_like
'not sending email'
end
context
'notifications are enabled only for default and protected branches '
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
'not sending email'
end
context
'notifications are enabled only for all branches'
do
before
do
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
'sending email'
end
end
end
end
...
...
spec/support/shared_examples/models/chat_service_shared_examples.rb
View file @
5c99ba03
...
...
@@ -70,14 +70,60 @@ shared_examples_for "chat service" do |service_name|
subject
.
execute
(
sample_data
)
end
context
"with
not
default branch"
do
context
"with default branch"
do
let
(
:sample_data
)
do
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
"not-the-default-branch"
)
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
project
.
default_branch
)
end
context
"when
notify_only_default_branch enabl
ed"
do
context
"when
only default branch are to be notifi
ed"
do
before
do
subject
.
notify_only_default_branch
=
true
subject
.
branches_to_be_notified
=
"default"
end
it_behaves_like
"
#{
service_name
}
service"
end
context
"when only protected branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it
"does not call the Discord Webhooks API"
do
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
end
end
context
"when default and protected branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
"
#{
service_name
}
service"
end
context
"when all branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
"
#{
service_name
}
service"
end
end
context
"with protected branch"
do
before
do
create
(
:protected_branch
,
project:
project
,
name:
"a-protected-branch"
)
end
let
(
:sample_data
)
do
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
"a-protected-branch"
)
end
context
"when only default branch are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"default"
end
it
"does not call the Discord Webhooks API"
do
...
...
@@ -87,9 +133,75 @@ shared_examples_for "chat service" do |service_name|
end
end
context
"when notify_only_default_branch disabled"
do
context
"when only protected branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it_behaves_like
"
#{
service_name
}
service"
end
context
"when default and protected branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
"
#{
service_name
}
service"
end
context
"when all branches are to be notified"
do
before
do
subject
.
notify_only_default_branch
=
false
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
"
#{
service_name
}
service"
end
end
context
"with neither default nor protected branch"
do
let
(
:sample_data
)
do
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
"a-random-branch"
)
end
context
"when only default branch are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"default"
end
it
"does not call the Discord Webhooks API"
do
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
end
end
context
"when only protected branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it
"does not call the Discord Webhooks API"
do
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
end
end
context
"when default and protected branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it
"does not call the Discord Webhooks API"
do
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
end
end
context
"when all branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
"
#{
service_name
}
service"
...
...
@@ -220,15 +332,86 @@ shared_examples_for "chat service" do |service_name|
end
end
context
"with not default branch"
do
context
"with protected branch"
do
before
do
create
(
:protected_branch
,
project:
project
,
name:
'a-protected-branch'
)
end
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
:failed
,
project:
project
,
sha:
project
.
commit
.
sha
,
ref:
"not-the-default-branch"
)
sha:
project
.
commit
.
sha
,
ref:
'a-protected-branch'
)
end
context
"when only default branch are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"default"
end
it
"does not call the Discord Webhooks API"
do
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
end
end
context
"when only protected branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it_behaves_like
"
#{
service_name
}
service"
end
context
"when default and protected branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it_behaves_like
"
#{
service_name
}
service"
end
context
"when all branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
"
#{
service_name
}
service"
end
end
context
"with neither default nor protected branch"
do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
:failed
,
project:
project
,
sha:
project
.
commit
.
sha
,
ref:
"a-random-branch"
)
end
context
"when only default branch are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"default"
end
it
"does not call the Discord Webhooks API"
do
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
end
end
context
"when only protected branches are to be notified"
do
before
do
subject
.
branches_to_be_notified
=
"protected"
end
it
"does not call the Discord Webhooks API"
do
result
=
subject
.
execute
(
sample_data
)
expect
(
result
).
to
be_falsy
end
end
context
"when
notify_only_default_branch enabl
ed"
do
context
"when
default and protected branches are to be notifi
ed"
do
before
do
subject
.
notify_only_default_branch
=
true
subject
.
branches_to_be_notified
=
"default_and_protected"
end
it
"does not call the Discord Webhooks API"
do
...
...
@@ -238,9 +421,9 @@ shared_examples_for "chat service" do |service_name|
end
end
context
"when
notify_only_default_branch disabl
ed"
do
context
"when
all branches are to be notifi
ed"
do
before
do
subject
.
notify_only_default_branch
=
false
subject
.
branches_to_be_notified
=
"all"
end
it_behaves_like
"
#{
service_name
}
service"
...
...
spec/support/shared_examples/slack_mattermost_notifications_shared_examples.rb
View file @
5c99ba03
...
...
@@ -269,29 +269,176 @@ RSpec.shared_examples 'slack or mattermost notifications' do
WebMock
.
stub_request
(
:post
,
webhook_url
)
end
context
'only notify for the default branch'
do
context
'when enabled'
do
context
'on default branch'
do
it
'still notifies about pushed tags'
do
ref
=
"
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}
test"
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
ref
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
context
'notification enabled only for default branch'
do
before
do
chat_service
.
notify_only_default_branch
=
true
chat_service
.
branches_to_be_notified
=
"default"
end
it
'does not notify push events if they are not for the default branch'
do
ref
=
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}
test"
it
'notifies about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
project
.
default_branch
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
)
end
end
context
'notification enabled only for protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"protected"
end
it
'does not notify about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
project
.
default_branch
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
not_to
have_requested
(
:post
,
webhook_url
).
once
end
end
context
'notification enabled only for default and protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"default_and_protected"
end
it
'notifies about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
project
.
default_branch
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
context
'notification enabled for all branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"all"
end
it
'notifies about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
project
.
default_branch
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
end
context
'on a protected branch'
do
before
do
create
(
:protected_branch
,
project:
project
,
name:
'a-protected-branch'
)
end
it
'still notifies about pushed tags'
do
ref
=
"
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}
test"
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
ref
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
context
'notification enabled only for default branch'
do
before
do
chat_service
.
branches_to_be_notified
=
"default"
end
it
'does not notify about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
'a-protected-branch'
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
not_to
have_requested
(
:post
,
webhook_url
)
end
end
context
'notification enabled only for protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"protected"
end
it
'notifies about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
'a-protected-branch'
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
context
'notification enabled only for default and protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"default_and_protected"
end
it
'notifies about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
'a-protected-branch'
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
it
'notifies about push events for the default branch'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build_sample
(
project
,
user
)
context
'notification enabled for all branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"all"
end
it
'notifies about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
'a-protected-branch'
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
end
end
context
'on a neither protected nor default branch'
do
it
'still notifies about pushed tags'
do
ref
=
"
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}
test"
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
ref
)
...
...
@@ -300,16 +447,72 @@ RSpec.shared_examples 'slack or mattermost notifications' do
expect
(
WebMock
).
to
have_requested
(
:post
,
webhook_url
).
once
end
context
'notification enabled only for default branch'
do
before
do
chat_service
.
branches_to_be_notified
=
"default"
end
it
'does not notify about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
'a-random-branch'
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
not_to
have_requested
(
:post
,
webhook_url
)
end
end
context
'
when disabled
'
do
context
'
notification enabled only for protected branches
'
do
before
do
chat_service
.
notify_only_default_branch
=
false
chat_service
.
branches_to_be_notified
=
"protected"
end
it
'notifies about all push events'
do
ref
=
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}
test"
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
ref
)
it
'does not notify about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
'a-random-branch'
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
not_to
have_requested
(
:post
,
webhook_url
).
once
end
end
context
'notification enabled only for default and protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"default_and_protected"
end
it
'does not notify about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
'a-random-branch'
)
chat_service
.
execute
(
push_sample_data
)
expect
(
WebMock
).
not_to
have_requested
(
:post
,
webhook_url
).
once
end
end
context
'notification enabled for all branches'
do
before
do
chat_service
.
branches_to_be_notified
=
"all"
end
it
'notifies about push events'
do
push_sample_data
=
Gitlab
::
DataBuilder
::
Push
.
build
(
project:
project
,
user:
user
,
ref:
'a-random-branch'
)
chat_service
.
execute
(
push_sample_data
)
...
...
@@ -451,15 +654,61 @@ RSpec.shared_examples 'slack or mattermost notifications' do
end
end
context
'only notify for the default branch'
do
context
'when enabled'
do
context
'on a default branch'
do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
:failed
,
project:
project
,
sha:
project
.
commit
.
sha
,
ref:
'not-the-default-branch'
)
create
(
:ci_pipeline
,
:failed
,
project:
project
,
sha:
project
.
commit
.
sha
,
ref:
project
.
default_branch
)
end
context
'notification enabled only for default branch'
do
before
do
chat_service
.
notify_only_default_branch
=
true
WebMock
.
stub_request
(
:post
,
webhook_url
)
chat_service
.
branches_to_be_notified
=
'default'
end
it_behaves_like
'call Slack/Mattermost API'
end
context
'notification enabled only for protected branch'
do
before
do
chat_service
.
branches_to_be_notified
=
'protected'
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
context
'notification enabled only for default and protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
'default_and_protected'
end
it_behaves_like
'call Slack/Mattermost API'
end
context
'notification enabled for all branches'
do
before
do
chat_service
.
branches_to_be_notified
=
'all'
end
it_behaves_like
'call Slack/Mattermost API'
end
end
context
'on a protected branch'
do
before
do
create
(
:protected_branch
,
project:
project
,
name:
'a-protected-branch'
)
end
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
:failed
,
project:
project
,
sha:
project
.
commit
.
sha
,
ref:
'a-protected-branch'
)
end
context
'notification enabled only for default branch'
do
before
do
chat_service
.
branches_to_be_notified
=
'default'
end
it
'does not call the Slack/Mattermost API for pipeline events'
do
...
...
@@ -470,13 +719,78 @@ RSpec.shared_examples 'slack or mattermost notifications' do
end
end
context
'when disabled'
do
context
'notification enabled only for protected branch'
do
before
do
chat_service
.
branches_to_be_notified
=
'protected'
end
it_behaves_like
'call Slack/Mattermost API'
end
context
'notification enabled only for default and protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
'default_and_protected'
end
it_behaves_like
'call Slack/Mattermost API'
end
context
'notification enabled for all branches'
do
before
do
chat_service
.
branches_to_be_notified
=
'all'
end
it_behaves_like
'call Slack/Mattermost API'
end
end
context
'on a neithuer protected nor default branch'
do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
:failed
,
project:
project
,
sha:
project
.
commit
.
sha
,
ref:
'not-the-default-branch'
)
create
(
:ci_pipeline
,
:failed
,
project:
project
,
sha:
project
.
commit
.
sha
,
ref:
'a-random-branch'
)
end
context
'notification enabled only for default branch'
do
before
do
chat_service
.
branches_to_be_notified
=
'default'
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
context
'notification enabled only for protected branch'
do
before
do
chat_service
.
branches_to_be_notified
=
'protected'
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
context
'notification enabled only for default and protected branches'
do
before
do
chat_service
.
branches_to_be_notified
=
'default_and_protected'
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
context
'notification enabled for all branches'
do
before
do
chat_service
.
notify_only_default_branch
=
false
chat_service
.
branches_to_be_notified
=
'all'
end
it_behaves_like
'call Slack/Mattermost API'
...
...
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