Split notification integration into another branch

This commit is contained in:
Lin Jen-Shin 2016-09-14 19:34:24 +08:00
parent 9d9c2d314c
commit 1404aa8677
5 changed files with 10 additions and 31 deletions

View File

@ -62,10 +62,6 @@ 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
@ -94,11 +90,6 @@ 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)")

View File

@ -32,9 +32,7 @@ class NotificationSetting < ActiveRecord::Base
:reopen_merge_request,
:close_merge_request,
:reassign_merge_request,
:merge_merge_request,
:failed_pipeline,
:success_pipeline
:merge_merge_request
]
store :events, accessors: EMAIL_EVENTS, coder: JSON

View File

@ -6,8 +6,14 @@ module Ci
@pipeline = new_pipeline
end
def execute(recipients = nil)
notification_service.pipeline_finished(pipeline, recipients)
def execute(recipients)
email_template = "pipeline_#{pipeline.status}_email"
return unless Notify.respond_to?(email_template)
recipients.each do |to|
Notify.public_send(email_template, pipeline, to).deliver_later
end
end
end
end

View File

@ -311,22 +311,6 @@ 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,
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
# Get project/group users with CUSTOM notification level

View File

@ -9,7 +9,7 @@ describe Ci::SendPipelineNotificationService, services: true do
shared_examples 'sending emails' do
it 'sends an email to pipeline user' do
perform_enqueued_jobs do
subject.execute
subject.execute([user.email])
end
email = ActionMailer::Base.deliveries.last