Commit f6f6aaf5 authored by Douwe Maan's avatar Douwe Maan Committed by Luke "Jared" Bennett

Better notification emails for notes and (diff) discussions

parent 76aa0bed
......@@ -4,7 +4,7 @@ module Emails
setup_note_mail(note_id, recipient_id)
@commit = @note.noteable
@discussion = @note.to_discussion if @note.diff_note?
@discussion = @note.discussion if @note.part_of_discussion?
@target_url = namespace_project_commit_url(*note_target_url_options)
mail_answer_thread(@commit,
......@@ -17,6 +17,7 @@ module Emails
setup_note_mail(note_id, recipient_id)
@issue = @note.noteable
@discussion = @note.discussion if @note.part_of_discussion?
@target_url = namespace_project_issue_url(*note_target_url_options)
mail_answer_thread(@issue, note_thread_options(recipient_id))
end
......@@ -25,7 +26,7 @@ module Emails
setup_note_mail(note_id, recipient_id)
@merge_request = @note.noteable
@discussion = @note.to_discussion if @note.diff_note?
@discussion = @note.discussion if @note.part_of_discussion?
@target_url = namespace_project_merge_request_url(*note_target_url_options)
mail_answer_thread(@merge_request, note_thread_options(recipient_id))
end
......@@ -34,6 +35,7 @@ module Emails
setup_note_mail(note_id, recipient_id)
@snippet = @note.noteable
@discussion = @note.discussion if @note.part_of_discussion?
@target_url = namespace_project_snippet_url(*note_target_url_options)
mail_answer_thread(@snippet, note_thread_options(recipient_id))
end
......@@ -42,6 +44,7 @@ module Emails
setup_note_mail(note_id, recipient_id)
@snippet = @note.noteable
@discussion = @note.discussion if @note.part_of_discussion?
@target_url = snippet_url(@note.noteable)
mail_answer_thread(@snippet, note_thread_options(recipient_id))
end
......
......@@ -4,12 +4,14 @@ class DiffDiscussion < Discussion
delegate :line_code,
:original_line_code,
:diff_file,
:diff_line,
:for_line?,
:active?,
to: :first_note
delegate :blob,
delegate :file_path,
:blob,
:highlighted_diff_lines,
:diff_lines,
......
......@@ -87,6 +87,10 @@ class Discussion
false
end
def new_discussion?
notes.length == 1
end
def potentially_resolvable?
first_note.for_merge_request?
end
......
......@@ -261,7 +261,7 @@ class Note < ActiveRecord::Base
# Returns the entire discussion this note is part of
def discussion
if part_of_discussion?
self.noteable.notes.find_discussion(self.discussion_id)
self.noteable.notes.find_discussion(self.discussion_id) || to_discussion
else
to_discussion
end
......
<%= yield -%>
---
You're receiving this email because of your account on <%= Gitlab.config.gitlab.host %>.
= yield
You're receiving this email because of your account on #{Gitlab.config.gitlab.host}.
Manage all notifications: #{profile_notifications_url}
Help: #{help_url}
<%= yield -%>
---
<% if @target_url -%>
<% if @reply_by_email -%>
<%= "Reply to this email directly or view it on GitLab: #{@target_url}" -%>
<% else -%>
<%= "View it on GitLab: #{@target_url}" -%>
<% end -%>
<% end -%>
You're receiving this email because of your account on <%= Gitlab.config.gitlab.host %>.
- if @discussion
%p.details
= succeed ':' do
= link_to @note.author_name, user_url(@note.author)
- if @discussion.diff_discussion?
- if @discussion.new_discussion?
started a new discussion
- else
commented on a discussion
on #{link_to @discussion.file_path, @target_url}
- else
- if @discussion.new_discussion?
started a new discussion
- else
commented on a #{link_to 'discussion', @target_url}
- elsif current_application_settings.email_author_in_body
%p.details
#{link_to @note.author_name, user_url(@note.author)} commented:
- if @discussion&.diff_discussion?
= content_for :head do
= stylesheet_link_tag 'mailers/highlighted_diff_email'
%table
= render partial: "projects/diffs/line",
collection: @discussion.truncated_diff_lines,
as: :line,
locals: { diff_file: @discussion.diff_file,
plain: true,
email: true }
%div
= markdown(@note.note, pipeline: :email, author: @note.author)
<% if @discussion -%>
<%= @note.author_name -%>
<% if @discussion.new_discussion? -%>
<%= " started a new discussion" -%>
<% else -%>
<%= " commented on a discussion" -%>
<% end -%>
<% if @discussion.diff_discussion? -%>
<%= " on #{@discussion.file_path}" -%>
<% end -%>
<%= ":" -%>
<% elsif current_application_settings.email_author_in_body -%>
<%= "#{@note.author_name} commented:" -%>
<% end -%>
<% if @discussion&.diff_discussion? -%>
<% @discussion.truncated_diff_lines(highlight: false).each do |line| -%>
<%= "> #{line.text}\n" -%>
<% end -%>
<% end -%>
<%= @note.note -%>
- if current_application_settings.email_author_in_body
%div
#{link_to @note.author_name, user_url(@note.author)} wrote:
%div
= markdown(@note.note, pipeline: :email, author: @note.author)
<% if current_application_settings.email_author_in_body %>
<%= @note.author_name %> wrote:
<% end -%>
<%= @note.note %>
= content_for :head do
= stylesheet_link_tag 'mailers/highlighted_diff_email'
New comment
- if @discussion && @discussion.diff_file
on
= link_to @note.diff_file.file_path, @target_url, class: 'details'
\:
%table
= render partial: "projects/diffs/line",
collection: @discussion.truncated_diff_lines,
as: :line,
locals: { diff_file: @note.diff_file,
plain: true,
email: true }
= render 'note_message'
<% if @discussion && @discussion.diff_file -%>
on <%= @note.diff_file.file_path -%>
<% end -%>:
<%= url %>
<%= render 'simple_diff' if @discussion -%>
<%= render 'note_message' %>
<% @discussion.truncated_diff_lines(highlight: false).each do |line| %>
> <%= line.text %>
<% end %>
%p.details
= render 'note_mr_or_commit_email'
= render 'note_email'
New comment for Commit <%= @commit.short_id -%>
<%= render partial: 'note_mr_or_commit_email', locals: { url: @target_url } %>
<%= render partial: 'note_email' %>
= render 'note_message'
= render 'note_email'
New comment for Issue <%= @issue.iid %>
<%= url_for(namespace_project_issue_url(@issue.project.namespace, @issue.project, @issue, anchor: "note_#{@note.id}")) %>
Author: <%= @note.author_name %>
<%= @note.note %>
<%= render partial: 'note_email' %>
%p.details
= render 'note_mr_or_commit_email'
= render 'note_email'
New comment for Merge Request <%= @merge_request.to_reference -%>
<%= render partial: 'note_mr_or_commit_email', locals: { url: @target_url }%>
<%= render partial: 'note_email'%>
New comment for Snippet <%= @snippet.id %>
<%= url_for(snippet_url(@snippet, anchor: "note_#{@note.id}")) %>
Author: <%= @note.author_name %>
<%= @note.note %>
<%= render partial: 'note_email' %>
= render 'note_message'
= render 'note_email'
New comment for Snippet <%= @snippet.id %>
<%= url_for(namespace_project_snippet_url(@snippet.project.namespace, @snippet.project, @snippet, anchor: "note_#{@note.id}")) %>
Author: <%= @note.author_name %>
<%= @note.note %>
<%= render partial: 'note_email' %>
......@@ -33,6 +33,10 @@ module Gitlab
new_pos unless removed? || meta?
end
def line
new_line || old_line
end
def unchanged?
type.nil?
end
......
......@@ -536,6 +536,8 @@ describe Notify do
allow(Note).to receive(:find).with(note.id).and_return(note)
end
# TODO: Test discussions
shared_examples 'a note email' do
it_behaves_like 'it should have Gmail Actions links'
......
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