summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-12-17 16:20:45 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-12-17 16:20:45 +0200
commit074efd8fd57736bcec25b2f08324b9d25aa886d5 (patch)
tree5f22a0a2e78ed917cbca5bca41ed1ebcb40f6782
parent8b89ef8639b2b6ee69d991fb0d6089f9437bbee2 (diff)
downloadgitlab-ce-074efd8fd57736bcec25b2f08324b9d25aa886d5.tar.gz
Email on push: dont send email if new branch was pushed or branch was removed
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/mailers/emails/projects.rb8
-rw-r--r--app/models/project_services/emails_on_push_service.rb11
-rw-r--r--app/views/notify/repository_push_email.html.haml2
-rw-r--r--app/views/notify/repository_push_email.text.haml2
4 files changed, 16 insertions, 7 deletions
diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb
index 809ce323958..df21d7b5b02 100644
--- a/app/mailers/emails/projects.rb
+++ b/app/mailers/emails/projects.rb
@@ -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
diff --git a/app/models/project_services/emails_on_push_service.rb b/app/models/project_services/emails_on_push_service.rb
index 1d4828fe720..8df7313f987 100644
--- a/app/models/project_services/emails_on_push_service.rb
+++ b/app/models/project_services/emails_on_push_service.rb
@@ -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
diff --git a/app/views/notify/repository_push_email.html.haml b/app/views/notify/repository_push_email.html.haml
index 48c3b3277bf..d0b30c08338 100644
--- a/app/views/notify/repository_push_email.html.haml
+++ b/app/views/notify/repository_push_email.html.haml
@@ -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:
diff --git a/app/views/notify/repository_push_email.text.haml b/app/views/notify/repository_push_email.text.haml
index 0da5b9513ee..6718ca68359 100644
--- a/app/views/notify/repository_push_email.text.haml
+++ b/app/views/notify/repository_push_email.text.haml
@@ -1,4 +1,4 @@
-New push to #{@branch} at #{@project.name_with_namespace}
+#{@author.name} pushed to #{@branch} at #{@project.name_with_namespace}
\
Commits: