Commit 074efd8fd57736bcec25b2f08324b9d25aa886d5
1 parent
8b89ef86
Exists in
master
and in
4 other branches
Email on push: dont send email if new branch was pushed or branch was removed
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
16 additions
and
7 deletions
Show diff stats
app/mailers/emails/projects.rb
... | ... | @@ -14,10 +14,10 @@ module Emails |
14 | 14 | subject: subject("Project was moved")) |
15 | 15 | end |
16 | 16 | |
17 | - def repository_push_email(project_id, recipient, branch, compare) | |
18 | - @project = Project.find project_id | |
19 | - @commits = Commit.decorate compare.commits | |
20 | - @commit = compare.commit | |
17 | + def repository_push_email(project_id, recipient, author_id, branch, compare) | |
18 | + @project = Project.find(project_id) | |
19 | + @author = User.find(author_id) | |
20 | + @commits = Commit.decorate(compare.commits) | |
21 | 21 | @diffs = compare.diffs |
22 | 22 | @branch = branch |
23 | 23 | ... | ... |
app/models/project_services/emails_on_push_service.rb
... | ... | @@ -36,11 +36,20 @@ class EmailsOnPushService < Service |
36 | 36 | before_sha = push_data[:before] |
37 | 37 | after_sha = push_data[:after] |
38 | 38 | branch = push_data[:ref] |
39 | + author_id = push_data[:user_id] | |
40 | + | |
41 | + if before_sha =~ /^000000/ || after_sha =~ /^000000/ | |
42 | + # skip if new branch was pushed or branch was removed | |
43 | + return true | |
44 | + end | |
39 | 45 | |
40 | 46 | compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) |
41 | 47 | |
48 | + # Do not send emails if git compare failed | |
49 | + return false unless compare && compare.commits.present? | |
50 | + | |
42 | 51 | recipients.split(" ").each do |recipient| |
43 | - Notify.delay.repository_push_email(project_id, recipient, branch, compare) | |
52 | + Notify.delay.repository_push_email(project_id, recipient, author_id, branch, compare) | |
44 | 53 | end |
45 | 54 | end |
46 | 55 | ... | ... |
app/views/notify/repository_push_email.html.haml
app/views/notify/repository_push_email.text.haml