Email on push: dont send email if new branch was pushed or branch was removed

Signed-off-by: NDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
上级 8b89ef86
......@@ -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
......
%h3 New push to #{@branch} at #{@project.name_with_namespace}
%h3 #{@author.name} pushed to #{@branch} at #{@project.name_with_namespace}
%h4 Commits:
......
New push to #{@branch} at #{@project.name_with_namespace}
#{@author.name} pushed to #{@branch} at #{@project.name_with_namespace}
\
Commits:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册