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:
Dmitriy Zaporozhets 2013-12-17 16:20:45 +02:00
parent 8b89ef8639
commit 074efd8fd5
No known key found for this signature in database
GPG Key ID: 627C5F589F467F17
4 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -1,4 +1,4 @@
New push to #{@branch} at #{@project.name_with_namespace}
#{@author.name} pushed to #{@branch} at #{@project.name_with_namespace}
\
Commits: