Commit 074efd8f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 8b89ef86
...@@ -14,10 +14,10 @@ module Emails ...@@ -14,10 +14,10 @@ module Emails
subject: subject("Project was moved")) subject: subject("Project was moved"))
end end
def repository_push_email(project_id, recipient, branch, compare) def repository_push_email(project_id, recipient, author_id, branch, compare)
@project = Project.find project_id @project = Project.find(project_id)
@commits = Commit.decorate compare.commits @author = User.find(author_id)
@commit = compare.commit @commits = Commit.decorate(compare.commits)
@diffs = compare.diffs @diffs = compare.diffs
@branch = branch @branch = branch
......
...@@ -36,11 +36,20 @@ class EmailsOnPushService < Service ...@@ -36,11 +36,20 @@ class EmailsOnPushService < Service
before_sha = push_data[:before] before_sha = push_data[:before]
after_sha = push_data[:after] after_sha = push_data[:after]
branch = push_data[:ref] 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) 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| 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
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: %h4 Commits:
......
New push to #{@branch} at #{@project.name_with_namespace} #{@author.name} pushed to #{@branch} at #{@project.name_with_namespace}
\ \
Commits: Commits:
......
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