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
4add6ca6
Commit
4add6ca6
authored
Sep 13, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try to integrate the email into notification system
parent
1b1c6ebf
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
51 additions
and
49 deletions
+51
-49
app/mailers/emails/pipelines.rb
app/mailers/emails/pipelines.rb
+7
-7
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+9
-0
app/models/notification_setting.rb
app/models/notification_setting.rb
+3
-1
app/models/project_services/pipelines_email_service.rb
app/models/project_services/pipelines_email_service.rb
+2
-1
app/services/ci/send_pipeline_notification_service.rb
app/services/ci/send_pipeline_notification_service.rb
+13
-0
app/services/notification_service.rb
app/services/notification_service.rb
+17
-1
app/views/notify/pipeline_success_email.html.haml
app/views/notify/pipeline_success_email.html.haml
+0
-0
app/views/notify/pipeline_success_email.text.erb
app/views/notify/pipeline_success_email.text.erb
+0
-0
app/workers/pipeline_email_worker.rb
app/workers/pipeline_email_worker.rb
+0
-39
No files found.
app/mailers/emails/pipelines.rb
View file @
4add6ca6
module
Emails
module
Pipelines
def
pipeline_succe
eded_email
(
params
,
to
)
pipeline_mail
(
p
arams
,
to
,
'succeeded'
)
def
pipeline_succe
ss_email
(
pipeline
,
to
)
pipeline_mail
(
p
ipeline
,
to
,
'succeeded'
)
end
def
pipeline_failed_email
(
p
arams
,
to
)
pipeline_mail
(
p
arams
,
to
,
'failed'
)
def
pipeline_failed_email
(
p
ipeline
,
to
)
pipeline_mail
(
p
ipeline
,
to
,
'failed'
)
end
private
def
pipeline_mail
(
p
arams
,
to
,
status
)
@project
=
p
arams
.
project
@pipeline
=
p
arams
.
p
ipeline
def
pipeline_mail
(
p
ipeline
,
to
,
status
)
@project
=
p
ipeline
.
project
@pipeline
=
pipeline
add_headers
mail
(
to:
to
,
subject:
pipeline_subject
(
status
))
...
...
app/models/ci/pipeline.rb
View file @
4add6ca6
...
...
@@ -62,6 +62,10 @@ module Ci
after_transition
do
|
pipeline
,
transition
|
pipeline
.
execute_hooks
unless
transition
.
loopback?
end
after_transition
any
=>
[
:success
,
:failed
]
do
|
pipeline
,
transition
|
SendPipelineNotificationService
.
new
(
pipeline
).
execute
end
end
# ref can't be HEAD or SHA, can only be branch/tag name
...
...
@@ -90,6 +94,11 @@ module Ci
project
.
id
end
# For now the only user who participants is the user who triggered
def
participants
(
current_user
=
nil
)
[
user
]
end
def
valid_commit_sha
if
self
.
sha
==
Gitlab
::
Git
::
BLANK_SHA
self
.
errors
.
add
(
:sha
,
" cant be 00000000 (branch removal)"
)
...
...
app/models/notification_setting.rb
View file @
4add6ca6
...
...
@@ -32,7 +32,9 @@ class NotificationSetting < ActiveRecord::Base
:reopen_merge_request
,
:close_merge_request
,
:reassign_merge_request
,
:merge_merge_request
:merge_merge_request
,
:failed_pipeline
,
:success_pipeline
]
store
:events
,
accessors:
EMAIL_EVENTS
,
coder:
JSON
...
...
app/models/project_services/pipelines_email_service.rb
View file @
4add6ca6
...
...
@@ -34,7 +34,8 @@ class PipelinesEmailService < Service
return
unless
all_recipients
.
any?
PipelineEmailWorker
.
perform_async
(
data
,
all_recipients
)
pipeline
=
Ci
::
Pipeline
.
find
(
data
[
:object_attributes
][
:id
])
Ci
::
SendPipelineNotificationService
.
new
(
pipeline
).
execute
(
all_recipients
)
end
def
can_test?
...
...
app/services/ci/send_pipeline_notification_service.rb
0 → 100644
View file @
4add6ca6
module
Ci
class
SendPipelineNotificationService
<
BaseService
attr_reader
:pipeline
def
initialize
(
new_pipeline
)
@pipeline
=
new_pipeline
end
def
execute
(
recipients
=
nil
)
notification_service
.
pipeline_finished
(
pipeline
,
recipients
)
end
end
end
app/services/notification_service.rb
View file @
4add6ca6
...
...
@@ -311,6 +311,22 @@ class NotificationService
mailer
.
project_was_not_exported_email
(
current_user
,
project
,
errors
).
deliver_later
end
def
pipeline_finished
(
pipeline
,
recipients
=
nil
)
email_template
=
"pipeline_
#{
pipeline
.
status
}
_email"
return
unless
mailer
.
respond_to?
(
email_template
)
recipients
||=
build_recipients
(
pipeline
,
pipeline
.
project
,
pipeline
.
user
,
action:
pipeline
.
status
)
recipients
.
each
do
|
to
|
Notify
.
public_send
(
email_template
,
pipeline
,
to
).
deliver_later
end
end
protected
# Get project/group users with CUSTOM notification level
...
...
@@ -613,6 +629,6 @@ class NotificationService
# Build event key to search on custom notification level
# Check NotificationSetting::EMAIL_EVENTS
def
build_custom_key
(
action
,
object
)
"
#{
action
}
_
#{
object
.
class
.
name
.
underscore
}
"
.
to_sym
"
#{
action
}
_
#{
object
.
class
.
model_name
.
name
.
underscore
}
"
.
to_sym
end
end
app/views/notify/pipeline_succe
eded
_email.html.haml
→
app/views/notify/pipeline_succe
ss
_email.html.haml
View file @
4add6ca6
File moved
app/views/notify/pipeline_succe
eded
_email.text.erb
→
app/views/notify/pipeline_succe
ss
_email.text.erb
View file @
4add6ca6
File moved
app/workers/pipeline_email_worker.rb
deleted
100644 → 0
View file @
1b1c6ebf
class
PipelineEmailWorker
include
Sidekiq
::
Worker
ParamsStruct
=
Struct
.
new
(
:pipeline
,
:project
,
:email_template
)
class
Params
<
ParamsStruct
def
initialize
(
pipeline_id
)
self
.
pipeline
=
Ci
::
Pipeline
.
find
(
pipeline_id
)
self
.
project
=
pipeline
.
project
self
.
email_template
=
case
pipeline
.
status
when
'success'
:pipeline_succeeded_email
when
'failed'
:pipeline_failed_email
end
end
end
def
perform
(
data
,
recipients
)
params
=
Params
.
new
(
data
[
'object_attributes'
][
'id'
])
return
unless
params
.
email_template
recipients
.
each
do
|
to
|
deliver
(
params
,
to
)
do
Notify
.
public_send
(
params
.
email_template
,
params
,
to
).
deliver_now
end
end
end
private
def
deliver
(
params
,
to
)
yield
# These are input errors and won't be corrected even if Sidekiq retries
rescue
Net
::
SMTPFatalError
,
Net
::
SMTPSyntaxError
=>
e
project_name
=
params
.
project
.
path_with_namespace
logger
.
info
(
"Failed to send email for
#{
project_name
}
to
#{
to
}
:
#{
e
}
"
)
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