Commit d01168a1 authored by Stan Hu's avatar Stan Hu

Fix diffs in text part of email-on-push messages

`safe_diff_files` directly modifies @message.diffs and was being called inside the HTML template
of the e-mail. By the time the text e-mail rendering occurs, the objects were already
wrapped by GitLab's diff helpers. This MR makes it explicit that the diff wrapper
will be used in both the text and HTML e-mail templates.

Closes gitlab-org/gitlab-ce#14497
parent 7cce76b6
......@@ -46,7 +46,7 @@
= diff.new_path
- unless @message.disable_diffs?
- diff_files = safe_diff_files(@message.diffs, @message.diff_refs)
- diff_files = @message.diffs
%h4 Changes:
- diff_files.each_with_index do |diff_file, i|
......
......@@ -28,17 +28,17 @@
\
\
Changes:
- @message.diffs.each do |diff|
- @message.diffs.each do |diff_file|
\
\=====================================
- if diff.deleted_file
#{diff.old_path} deleted
- elsif diff.renamed_file
#{diff.old_path}#{diff.new_path}
- if diff_file.deleted_file
#{diff_file.old_path} deleted
- elsif diff_file.renamed_file
#{diff_file.old_path}#{diff_file.new_path}
- else
= diff.new_path
= diff_file.new_path
\=====================================
!= diff.diff
!= diff_file.diff.diff
- if @message.compare_timeout
\
\
......
......@@ -6,6 +6,7 @@ module Gitlab
attr_reader :author_id, :ref, :action
include Gitlab::Routing.url_helpers
include DiffHelper
delegate :namespace, :name_with_namespace, to: :project, prefix: :project
delegate :name, to: :author, prefix: :author
......@@ -38,7 +39,7 @@ module Gitlab
end
def diffs
@diffs ||= (compare.diffs if compare)
@diffs ||= (safe_diff_files(compare.diffs, diff_refs) if compare)
end
def diffs_count
......
......@@ -57,7 +57,7 @@ describe Gitlab::Email::Message::RepositoryPush do
describe '#diffs' do
subject { message.diffs }
it { is_expected.to all(be_an_instance_of Gitlab::Git::Diff) }
it { is_expected.to all(be_an_instance_of Gitlab::Diff::File) }
end
describe '#diffs_count' do
......
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