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
79b0cc0d
Commit
79b0cc0d
authored
Aug 28, 2019
by
Balasankar "Balu" C
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add branch specification to email service also
Signed-off-by:
Balasankar "Balu" C
<
balasankar@gitlab.com
>
parent
06011474
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
9 deletions
+42
-9
app/models/project_services/pipelines_email_service.rb
app/models/project_services/pipelines_email_service.rb
+39
-6
lib/api/helpers/services_helpers.rb
lib/api/helpers/services_helpers.rb
+3
-3
No files found.
app/models/project_services/pipelines_email_service.rb
View file @
79b0cc0d
# frozen_string_literal: true
class
PipelinesEmailService
<
Service
prop_accessor
:recipients
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
self
.
properties
||=
{
notify_only_broken_pipelines:
true
,
notify_only_default_branch:
false
}
if
properties
.
nil?
self
.
properties
=
{}
self
.
notify_only_broken_pipelines
=
true
self
.
branches_to_be_notified
=
"default"
elsif
!
self
.
notify_only_default_branch
.
nil?
&&
self
.
branches_to_be_notified
.
nil?
# In older versions, there was only a boolean property named
# `notify_only_default_branch`. Now we have a string property named
# `branches_to_be_notified`. Instead of doing a background migration, we
# opted to set a value for the new property based on the old one, if
# users hasn't specified one already. When users edit the service and
# selects a value for this new property, it will override everything.
self
.
branches_to_be_notified
=
notify_only_default_branch?
?
"default"
:
"all"
end
end
def
title
...
...
@@ -55,8 +75,9 @@ class PipelinesEmailService < Service
required:
true
},
{
type:
'checkbox'
,
name:
'notify_only_broken_pipelines'
},
{
type:
'checkbox'
,
name:
'notify_only_default_branch'
}
{
type:
'select'
,
name:
'branches_to_be_notified'
,
choices:
BRANCH_CHOICES
}
]
end
...
...
@@ -73,9 +94,21 @@ class PipelinesEmailService < Service
end
def
notify_for_pipeline_branch?
(
data
)
return
true
unless
notify_only_default_branch?
ref
=
if
data
[
:ref
]
Gitlab
::
Git
.
ref_name
(
data
[
:ref
])
else
data
.
dig
(
:object_attributes
,
:ref
)
end
data
[
:object_attributes
][
:ref
]
==
data
[
:project
][
:default_branch
]
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
end
def
notify_for_pipeline?
(
data
)
...
...
lib/api/helpers/services_helpers.rb
View file @
79b0cc0d
...
...
@@ -540,9 +540,9 @@ module API
},
{
required:
false
,
name: :
notify_only_default_branch
,
type:
Boolean
,
desc:
'
Send notifications only for the default branch
'
name: :
branches_to_be_notified
,
type:
String
,
desc:
'
Branches for which notifications are to be sent
'
}
],
'pivotaltracker'
=>
[
...
...
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