Commit 5d863321 authored by Douwe Maan's avatar Douwe Maan

Send EmailsOnPush when deleting commits using force push.

See #1924.
parent 769f137a
...@@ -16,9 +16,10 @@ module Emails ...@@ -16,9 +16,10 @@ module Emails
subject: subject("Project was moved")) subject: subject("Project was moved"))
end 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) @project = Project.find(project_id)
@author = User.find(author_id) @author = User.find(author_id)
@reverse_compare = reverse_compare
@compare = compare @compare = compare
@commits = Commit.decorate(compare.commits) @commits = Commit.decorate(compare.commits)
@diffs = compare.diffs @diffs = compare.diffs
...@@ -32,10 +33,13 @@ module Emails ...@@ -32,10 +33,13 @@ module Emails
@project, @project,
from: @commits.first, from: @commits.first,
to: @commits.last) to: @commits.last)
@subject << "Deleted " if @reverse_compare
@subject << "#{@commits.length} commits: #{@commits.first.title}" @subject << "#{@commits.length} commits: #{@commits.first.title}"
else else
@target_url = namespace_project_commit_url(@project.namespace, @target_url = namespace_project_commit_url(@project.namespace,
@project, @commits.first) @project, @commits.first)
@subject << "Deleted 1 commit: " if @reverse_compare
@subject << @commits.first.title @subject << @commits.first.title
end end
......
%h3 #{@author.name} pushed to #{@branch} at #{link_to @project.name_with_namespace, namespace_project_url(@project.namespace, @project)} %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 %ul
- @commits.each do |commit| - @commits.each do |commit|
......
#{@author.name} pushed to #{@branch} at #{@project.name_with_namespace} #{@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| - @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} #{commit.safe_message}
\- - - - - \- - - - -
\ \
......
...@@ -15,8 +15,15 @@ class EmailsOnPushWorker ...@@ -15,8 +15,15 @@ class EmailsOnPushWorker
compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha)
# Do not send emails if git compare failed return false if compare.same
return false unless compare && compare.commits.present?
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| recipients.split(" ").each do |recipient|
Notify.repository_push_email( Notify.repository_push_email(
...@@ -25,6 +32,7 @@ class EmailsOnPushWorker ...@@ -25,6 +32,7 @@ class EmailsOnPushWorker
author_id, author_id,
branch, branch,
compare, compare,
reverse_compare,
send_from_committer_email, send_from_committer_email,
disable_diffs disable_diffs
).deliver ).deliver
......
...@@ -571,7 +571,7 @@ describe Notify do ...@@ -571,7 +571,7 @@ describe Notify do
let(:diff_path) { namespace_project_compare_path(project.namespace, project, from: commits.first, to: commits.last) } let(:diff_path) { namespace_project_compare_path(project.namespace, project, from: commits.first, to: commits.last) }
let(:send_from_committer_email) { false } 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 it 'is sent as the author' do
sender = subject.header[:from].addrs[0] sender = subject.header[:from].addrs[0]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment