Commit 8ea702cf authored by Lin Jen-Shin's avatar Lin Jen-Shin

Revert "Split notification integration into another branch"

This reverts commit 1404aa86.
parent 7f7c3e1a
...@@ -82,6 +82,10 @@ module Ci ...@@ -82,6 +82,10 @@ module Ci
PipelineHooksWorker.perform_async(id) PipelineHooksWorker.perform_async(id)
end end
end end
after_transition any => [:success, :failed] do |pipeline, transition|
SendPipelineNotificationService.new(pipeline).execute
end
end end
# ref can't be HEAD or SHA, can only be branch/tag name # ref can't be HEAD or SHA, can only be branch/tag name
...@@ -110,6 +114,11 @@ module Ci ...@@ -110,6 +114,11 @@ module Ci
project.id project.id
end end
# For now the only user who participants is the user who triggered
def participants(current_user = nil)
[user]
end
def valid_commit_sha def valid_commit_sha
if self.sha == Gitlab::Git::BLANK_SHA if self.sha == Gitlab::Git::BLANK_SHA
self.errors.add(:sha, " cant be 00000000 (branch removal)") self.errors.add(:sha, " cant be 00000000 (branch removal)")
......
...@@ -32,7 +32,9 @@ class NotificationSetting < ActiveRecord::Base ...@@ -32,7 +32,9 @@ class NotificationSetting < ActiveRecord::Base
:reopen_merge_request, :reopen_merge_request,
:close_merge_request, :close_merge_request,
:reassign_merge_request, :reassign_merge_request,
:merge_merge_request :merge_merge_request,
:failed_pipeline,
:success_pipeline
] ]
store :events, accessors: EMAIL_EVENTS, coder: JSON store :events, accessors: EMAIL_EVENTS, coder: JSON
......
...@@ -6,14 +6,8 @@ module Ci ...@@ -6,14 +6,8 @@ module Ci
@pipeline = new_pipeline @pipeline = new_pipeline
end end
def execute(recipients) def execute(recipients = nil)
email_template = "pipeline_#{pipeline.status}_email" notification_service.pipeline_finished(pipeline, recipients)
return unless Notify.respond_to?(email_template)
recipients.each do |to|
Notify.public_send(email_template, pipeline, to).deliver_later
end
end end
end end
end end
...@@ -312,6 +312,22 @@ class NotificationService ...@@ -312,6 +312,22 @@ class NotificationService
mailer.project_was_not_exported_email(current_user, project, errors).deliver_later mailer.project_was_not_exported_email(current_user, project, errors).deliver_later
end 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,
nil, # The acting user, who won't be added to recipients
action: pipeline.status)
recipients.each do |to|
mailer.public_send(email_template, pipeline, to.email).deliver_later
end
end
protected protected
# Get project/group users with CUSTOM notification level # Get project/group users with CUSTOM notification level
......
...@@ -23,7 +23,7 @@ describe Ci::SendPipelineNotificationService, services: true do ...@@ -23,7 +23,7 @@ describe Ci::SendPipelineNotificationService, services: true do
shared_examples 'sending emails' do shared_examples 'sending emails' do
it 'sends emails' do it 'sends emails' do
perform_enqueued_jobs do perform_enqueued_jobs do
subject.execute([user.email]) subject.execute
end end
expected_receivers = [pusher, watcher].uniq.sort_by(&:email) expected_receivers = [pusher, watcher].uniq.sort_by(&:email)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment