diff options
-rw-r--r-- | app/mailers/emails/projects.rb | 6 | ||||
-rw-r--r-- | app/views/notify/repository_push_email.html.haml | 8 | ||||
-rw-r--r-- | app/views/notify/repository_push_email.text.haml | 10 | ||||
-rw-r--r-- | app/workers/emails_on_push_worker.rb | 12 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 2 |
5 files changed, 30 insertions, 8 deletions
diff --git a/app/mailers/emails/projects.rb b/app/mailers/emails/projects.rb index 30959ab6a1e..5c38601c1ba 100644 --- a/app/mailers/emails/projects.rb +++ b/app/mailers/emails/projects.rb @@ -16,9 +16,10 @@ module Emails subject: subject("Project was moved")) end - def repository_push_email(project_id, recipient, author_id, branch, compare, send_from_committer_email = false, disable_diffs = false) + def repository_push_email(project_id, recipient, author_id, branch, compare, reverse_compare = false, send_from_committer_email = false, disable_diffs = false) @project = Project.find(project_id) @author = User.find(author_id) + @reverse_compare = reverse_compare @compare = compare @commits = Commit.decorate(compare.commits) @diffs = compare.diffs @@ -32,10 +33,13 @@ module Emails @project, from: @commits.first, to: @commits.last) + @subject << "Deleted " if @reverse_compare @subject << "#{@commits.length} commits: #{@commits.first.title}" else @target_url = namespace_project_commit_url(@project.namespace, @project, @commits.first) + + @subject << "Deleted 1 commit: " if @reverse_compare @subject << @commits.first.title end diff --git a/app/views/notify/repository_push_email.html.haml b/app/views/notify/repository_push_email.html.haml index 1a617e2108d..039b92df2be 100644 --- a/app/views/notify/repository_push_email.html.haml +++ b/app/views/notify/repository_push_email.html.haml @@ -1,6 +1,12 @@ %h3 #{@author.name} pushed to #{@branch} at #{link_to @project.name_with_namespace, namespace_project_url(@project.namespace, @project)} -%h4 Commits: +- if @reverse_compare + %p + %strong WARNING: + The push did not contain any new commits, but force pushed to delete the commits and changes below. + +%h4 + = @reverse_compare ? "Deleted commits:" : "Commits:" %ul - @commits.each do |commit| diff --git a/app/views/notify/repository_push_email.text.haml b/app/views/notify/repository_push_email.text.haml index 7cb2814a492..8d67a42234e 100644 --- a/app/views/notify/repository_push_email.text.haml +++ b/app/views/notify/repository_push_email.text.haml @@ -1,9 +1,13 @@ #{@author.name} pushed to #{@branch} at #{@project.name_with_namespace} - \ -Commits: +\ +- if @reverse_compare + WARNING: The push did not contain any new commits, but force pushed to delete the commits and changes below. + \ + \ += @reverse_compare ? "Deleted commits:" : "Commits:" - @commits.each do |commit| - #{commit.short_id} by #{commit.author_name} + #{commit.short_id} by #{commit.author_name} at #{commit.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ")} #{commit.safe_message} \- - - - - \ diff --git a/app/workers/emails_on_push_worker.rb b/app/workers/emails_on_push_worker.rb index 309772cb5ce..2e783814824 100644 --- a/app/workers/emails_on_push_worker.rb +++ b/app/workers/emails_on_push_worker.rb @@ -15,8 +15,15 @@ class EmailsOnPushWorker 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? + return false if compare.same + + if compare.commits.empty? + compare = Gitlab::Git::Compare.new(project.repository.raw_repository, after_sha, before_sha) + + reverse_compare = true + + return false if compare.commits.empty? + end recipients.split(" ").each do |recipient| Notify.repository_push_email( @@ -25,6 +32,7 @@ class EmailsOnPushWorker author_id, branch, compare, + reverse_compare, send_from_committer_email, disable_diffs ).deliver diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index ad2b7c11f84..9af17942612 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -571,7 +571,7 @@ describe Notify do let(:diff_path) { namespace_project_compare_path(project.namespace, project, from: commits.first, to: commits.last) } let(:send_from_committer_email) { false } - subject { Notify.repository_push_email(project.id, 'devs@company.name', user.id, 'master', compare, send_from_committer_email) } + subject { Notify.repository_push_email(project.id, 'devs@company.name', user.id, 'master', compare, false, send_from_committer_email) } it 'is sent as the author' do sender = subject.header[:from].addrs[0] |