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
2a86722a
Commit
2a86722a
authored
Aug 28, 2019
by
Balasankar "Balu" C
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract notify_for_branch method to a general module
Signed-off-by:
Balasankar "Balu" C
<
balasankar@gitlab.com
>
parent
79b0cc0d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
53 deletions
+40
-53
app/models/project_services/chat_notification_service.rb
app/models/project_services/chat_notification_service.rb
+2
-27
app/models/project_services/notification_branch_selection.rb
app/models/project_services/notification_branch_selection.rb
+35
-0
app/models/project_services/pipelines_email_service.rb
app/models/project_services/pipelines_email_service.rb
+3
-26
No files found.
app/models/project_services/chat_notification_service.rb
View file @
2a86722a
...
...
@@ -4,6 +4,7 @@
# This class is not meant to be used directly, but only to inherit from.
class
ChatNotificationService
<
Service
include
ChatMessage
include
NotificationBranchSelection
SUPPORTED_EVENTS
=
%w[
push issue confidential_issue merge_request note confidential_note
...
...
@@ -23,13 +24,6 @@ class ChatNotificationService < Service
validates
:webhook
,
presence:
true
,
public_url:
true
,
if: :activated?
BRANCH_CHOICES
=
[
[
'All branches'
,
'all'
],
[
'Default branch'
,
'default'
],
[
'Protected branches'
,
'protected'
],
[
'Default branch and protected branches'
,
'default_and_protected'
]
].
freeze
def
initialize_properties
if
properties
.
nil?
self
.
properties
=
{}
...
...
@@ -185,26 +179,7 @@ class ChatNotificationService < Service
return
true
if
data
[
:object_kind
]
==
'tag_push'
return
true
if
data
.
dig
(
:object_attributes
,
:tag
)
ref
=
if
data
[
:ref
]
Gitlab
::
Git
.
ref_name
(
data
[
:ref
])
else
data
.
dig
(
:object_attributes
,
:ref
)
end
is_default_branch
=
ref
==
project
.
default_branch
is_protected_branch
=
project
.
protected_branches
.
exists?
(
name:
ref
)
if
branches_to_be_notified
==
"all"
true
elsif
branches_to_be_notified
==
"default"
is_default_branch
elsif
branches_to_be_notified
==
"protected"
is_protected_branch
elsif
branches_to_be_notified
==
"default_and_protected"
is_default_branch
||
is_protected_branch
else
false
end
notify_for_branch?
(
data
)
end
def
notify_for_pipeline?
(
data
)
...
...
app/models/project_services/notification_branch_selection.rb
0 → 100644
View file @
2a86722a
# frozen_string_literal: true
# This module will be included in ChatNotificationService and
# PipelinesEmailService classes. Not to be used directly.
module
NotificationBranchSelection
BRANCH_CHOICES
=
[
[
'All branches'
,
'all'
],
[
'Default branch'
,
'default'
],
[
'Protected branches'
,
'protected'
],
[
'Default branch and protected branches'
,
'default_and_protected'
]
].
freeze
def
notify_for_branch?
(
data
)
ref
=
if
data
[
:ref
]
Gitlab
::
Git
.
ref_name
(
data
[
:ref
])
else
data
.
dig
(
:object_attributes
,
:ref
)
end
is_default_branch
=
ref
==
project
.
default_branch
is_protected_branch
=
project
.
protected_branches
.
exists?
(
name:
ref
)
if
branches_to_be_notified
==
"all"
true
elsif
branches_to_be_notified
==
"default"
is_default_branch
elsif
branches_to_be_notified
==
"protected"
is_protected_branch
elsif
branches_to_be_notified
==
"default_and_protected"
is_default_branch
||
is_protected_branch
else
false
end
end
end
app/models/project_services/pipelines_email_service.rb
View file @
2a86722a
# frozen_string_literal: true
class
PipelinesEmailService
<
Service
include
NotificationBranchSelection
prop_accessor
:recipients
,
:branches_to_be_notified
boolean_accessor
:notify_only_broken_pipelines
,
:notify_only_default_branch
validates
:recipients
,
presence:
true
,
if: :valid_recipients?
BRANCH_CHOICES
=
[
[
'All branches'
,
'all'
],
[
'Default branch'
,
'default'
],
[
'Protected branches'
,
'protected'
],
[
'Default branch and protected branches'
,
'default_and_protected'
]
].
freeze
def
initialize_properties
if
properties
.
nil?
self
.
properties
=
{}
...
...
@@ -90,25 +85,7 @@ class PipelinesEmailService < Service
end
def
should_pipeline_be_notified?
(
data
)
notify_for_pipeline_branch?
(
data
)
&&
notify_for_pipeline?
(
data
)
end
def
notify_for_pipeline_branch?
(
data
)
ref
=
if
data
[
:ref
]
Gitlab
::
Git
.
ref_name
(
data
[
:ref
])
else
data
.
dig
(
:object_attributes
,
:ref
)
end
if
branches_to_be_notified
==
"all"
true
elsif
%w[default default_and_protected]
.
include?
(
branches_to_be_notified
)
ref
==
project
.
default_branch
elsif
%w[protected default_and_protected]
.
include?
(
branches_to_be_notified
)
project
.
protected_branches
.
exists?
(
name:
ref
)
else
false
end
notify_for_branch?
(
data
)
&&
notify_for_pipeline?
(
data
)
end
def
notify_for_pipeline?
(
data
)
...
...
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