summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhhoopes <heidih@gmail.com>2016-08-17 16:27:01 -0600
committerSean McGivern <sean@gitlab.com>2016-11-25 15:23:49 +0000
commit38ed96e9b1a47dca5aa2590fa9b0ade908337435 (patch)
tree17eca90234faa03e95a963b8820659fd03d90560
parent838c1aad68e8c7f81a0b8778f46f0ce4e7c5439d (diff)
downloadgitlab-ce-38ed96e9b1a47dca5aa2590fa9b0ade908337435.tar.gz
Add diff hunks to notification emails on MR
Added diff hunks to notification emails of messages on merge requests. This provides code context to the note. Uses existing template for formatting a diff for email (from repository push notifications).
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/assets/stylesheets/mailers/highlighted_diff_email.scss (renamed from app/assets/stylesheets/mailers/repository_push_email.scss)0
-rw-r--r--app/views/notify/note_merge_request_email.html.haml8
-rw-r--r--app/views/notify/repository_push_email.html.haml2
-rw-r--r--spec/mailers/notify_spec.rb19
5 files changed, 27 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 549336e4dff..56f749e94ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -797,6 +797,7 @@ entry.
## 8.11.0 (2016-08-22)
- Use test coverage value from the latest successful pipeline in badge. !5862
+ - Add git diff context to notifications of new notes on merge requests !5855 (hoopes)
- Add test coverage report badge. !5708
- Remove the http_parser.rb dependency by removing the tinder gem. !5758 (tbalthazar)
- Add Koding (online IDE) integration
diff --git a/app/assets/stylesheets/mailers/repository_push_email.scss b/app/assets/stylesheets/mailers/highlighted_diff_email.scss
index 8d1a6020ca4..8d1a6020ca4 100644
--- a/app/assets/stylesheets/mailers/repository_push_email.scss
+++ b/app/assets/stylesheets/mailers/highlighted_diff_email.scss
diff --git a/app/views/notify/note_merge_request_email.html.haml b/app/views/notify/note_merge_request_email.html.haml
index ea7e3d199fd..de3f32e6415 100644
--- a/app/views/notify/note_merge_request_email.html.haml
+++ b/app/views/notify/note_merge_request_email.html.haml
@@ -1,7 +1,15 @@
+= content_for :head do
+ = stylesheet_link_tag 'mailers/highlighted_diff_email'
+
- if @note.diff_note? && @note.diff_file
%p.details
New comment on diff for
= link_to @note.diff_file.file_path, @target_url
\:
+ .diff-content.code.js-syntax-highlight
+ %table
+ - Discussion.new([@note]).truncated_diff_lines.each do |line|
+ = render "projects/diffs/line", line: line, diff_file: @note.diff_file, plain: true
+
= render 'note_message'
diff --git a/app/views/notify/repository_push_email.html.haml b/app/views/notify/repository_push_email.html.haml
index 307c5a11206..25883de257c 100644
--- a/app/views/notify/repository_push_email.html.haml
+++ b/app/views/notify/repository_push_email.html.haml
@@ -1,5 +1,5 @@
= content_for :head do
- = stylesheet_link_tag 'mailers/repository_push_email'
+ = stylesheet_link_tag 'mailers/highlighted_diff_email'
%h3
#{@message.author_name} #{@message.action_name} #{@message.ref_type} #{@message.ref_name}
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 932a5dc4862..b40a6b1cbac 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -580,8 +580,10 @@ describe Notify do
let(:note_author) { create(:user, name: 'author_name') }
let(:note) { create(:note, project: project, author: note_author) }
- before :each do
- allow(Note).to receive(:find).with(note.id).and_return(note)
+ before do |example|
+ unless example.metadata[:skip_before]
+ allow(Note).to receive(:find).with(note.id).and_return(note)
+ end
end
shared_examples 'a note email' do
@@ -663,6 +665,19 @@ describe Notify do
end
end
+ describe "on a merge request with diffs", :skip_before do
+ let(:merge_request) { create(:merge_request_with_diffs) }
+ let(:note_with_diff) {create(:diff_note_on_merge_request)}
+
+ before(:each) { allow(note_with_diff).to receive(:noteable).and_return(merge_request) }
+ subject { Notify.note_merge_request_email(recipient.id, note_with_diff.id) }
+
+ it 'includes diffs with character-level highlighting' do
+ expected_line_text = Discussion.new([note_with_diff]).truncated_diff_lines.first.text
+ is_expected.to have_body_text expected_line_text
+ end
+ end
+
describe 'on an issue' do
let(:issue) { create(:issue, project: project) }
let(:note_on_issue_path) { namespace_project_issue_path(project.namespace, project, issue, anchor: "note_#{note.id}") }