Email on push: dont send email if new branch was pushed or branch was removed
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
8b89ef8639
commit
074efd8fd5
4 changed files with 16 additions and 7 deletions
|
@ -14,10 +14,10 @@ module Emails
|
|||
subject: subject("Project was moved"))
|
||||
end
|
||||
|
||||
def repository_push_email(project_id, recipient, branch, compare)
|
||||
@project = Project.find project_id
|
||||
@commits = Commit.decorate compare.commits
|
||||
@commit = compare.commit
|
||||
def repository_push_email(project_id, recipient, author_id, branch, compare)
|
||||
@project = Project.find(project_id)
|
||||
@author = User.find(author_id)
|
||||
@commits = Commit.decorate(compare.commits)
|
||||
@diffs = compare.diffs
|
||||
@branch = branch
|
||||
|
||||
|
|
|
@ -36,11 +36,20 @@ class EmailsOnPushService < Service
|
|||
before_sha = push_data[:before]
|
||||
after_sha = push_data[:after]
|
||||
branch = push_data[:ref]
|
||||
author_id = push_data[:user_id]
|
||||
|
||||
if before_sha =~ /^000000/ || after_sha =~ /^000000/
|
||||
# skip if new branch was pushed or branch was removed
|
||||
return true
|
||||
end
|
||||
|
||||
compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha)
|
||||
|
||||
# Do not send emails if git compare failed
|
||||
return false unless compare && compare.commits.present?
|
||||
|
||||
recipients.split(" ").each do |recipient|
|
||||
Notify.delay.repository_push_email(project_id, recipient, branch, compare)
|
||||
Notify.delay.repository_push_email(project_id, recipient, author_id, branch, compare)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
%h3 New push to #{@branch} at #{@project.name_with_namespace}
|
||||
%h3 #{@author.name} pushed to #{@branch} at #{@project.name_with_namespace}
|
||||
|
||||
%h4 Commits:
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
New push to #{@branch} at #{@project.name_with_namespace}
|
||||
#{@author.name} pushed to #{@branch} at #{@project.name_with_namespace}
|
||||
|
||||
\
|
||||
Commits:
|
||||
|
|
Loading…
Reference in a new issue