diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-02-25 17:12:19 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-02-25 17:12:19 +0300 |
commit | 5d86332153838252384f9f87a0ae3e34c46eb266 (patch) | |
tree | 47de3c1f04c5b2302f6269d6284d68cd29158214 /app | |
parent | 769f137a5344dbc3748c2fea7c1d560392410ca4 (diff) |
Send EmailsOnPush when deleting commits using force push.
See #1924.
Diffstat (limited to 'app')
-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 |
4 files changed, 29 insertions, 7 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 |