Commit d73a18fe authored by Douwe Maan's avatar Douwe Maan Committed by Robert Speicher

Add full diff highlighting to EmailsOnPush

parent 02f3a6e0
......@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.6.0 (unreleased)
- Improve weight filter for issues
- Add full diff highlighting to Email on push
- [Elastic] Add elastic checker to gitlab:check
- [Elastic] Added UPDATE_INDEX option to rake task
- [Elastic] Removing repository and wiki index after removing project
......
@import "framework/variables";
table.code {
width: 100%;
font-family: $monospace_font;
border: none;
border-collapse: separate;
margin: 0px;
padding: 0px;
-premailer-cellpadding: 0;
-premailer-cellspacing: 0;
-premailer-width: 100%;
td {
line-height: $code_line_height;
font-size: $code_font_size;
}
td.diff-line-num {
margin: 0px;
padding: 0px;
border: none;
background: $background-color;
color: rgba(0, 0, 0, 0.3);
padding: 0px 5px;
border-right: 1px solid $border-color;
text-align: right;
min-width: 35px;
max-width: 50px;
width: 35px;
}
td.line_content {
display: block;
margin: 0px;
padding: 0px 0.5em;
border: none;
white-space: pre;
}
}
@import "highlight/white";
......@@ -32,12 +32,6 @@ module EmailsHelper
nil
end
def color_email_diff(diffcontent)
formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', inline_theme: 'github')
lexer = Rouge::Lexers::Diff
raw formatter.format(lexer.lex(diffcontent))
end
def password_reset_token_valid_time
valid_hours = Devise.reset_password_within / 60 / 60
if valid_hours >= 24
......@@ -56,4 +50,10 @@ module EmailsHelper
msg = "This link is valid for #{password_reset_token_valid_time}. "
msg << "After it expires, you can #{link_tag}."
end
# Overrides
def diff_hard_limit_enabled?
false
end
end
......@@ -11,6 +11,8 @@ class Notify < BaseMailer
include Emails::Builds
add_template_helper MergeRequestsHelper
add_template_helper DiffHelper
add_template_helper BlobHelper
add_template_helper EmailsHelper
def test_email(recipient_email, subject, body)
......
......@@ -4,6 +4,7 @@
%title
GitLab
= stylesheet_link_tag 'notify'
= yield :head
%body
%div.content
= yield
......
= content_for :head do
= stylesheet_link_tag 'mailers/repository_push_email'
%h3
#{@message.author_name} #{@message.action_name} #{@message.ref_type} #{@message.ref_name}
at #{link_to(@message.project_name_with_namespace, namespace_project_url(@message.project_namespace, @message.project))}
......@@ -43,25 +46,34 @@
= diff.new_path
- unless @message.disable_diffs?
- diff_files = safe_diff_files(@message.diffs, @message.diff_refs)
%h4 Changes:
- @message.diffs.each_with_index do |diff, i|
- diff_files.each_with_index do |diff_file, i|
%li{id: "diff-#{i}"}
%a{href: @message.target_url + "#diff-#{i}"}
- if diff.deleted_file
- if diff_file.deleted_file
%strong
= diff.old_path
= diff_file.old_path
deleted
- elsif diff.renamed_file
- elsif diff_file.renamed_file
%strong
= diff.old_path
= diff_file.old_path
&rarr;
%strong
= diff.new_path
= diff_file.new_path
- else
%strong
= diff.new_path
= diff_file.new_path
%hr
= color_email_diff(diff.diff)
- diff_commit = diff_file.deleted_file ? @message.diff_refs.first : @message.diff_refs.last
- blob = @message.project.repository.blob_for_diff(diff_commit, diff_file)
- if blob && blob.respond_to?(:text?) && blob_text_viewable?(blob)
%table.code.white
- diff_file.highlighted_diff_lines.each do |line|
= render "projects/diffs/line", {line: line, diff_file: diff_file, line_code: nil, plain: true}
- else
No preview for this file type
%br
- if @message.compare_timeout
......
......@@ -40,8 +40,8 @@
= view_file_btn(diff_commit.id, diff_file, project)
.diff-content.diff-wrap-lines
-# Skipp all non non-supported blobs
- return unless blob.respond_to?('text?')
-# Skip all non-supported blobs
- return unless blob.respond_to?(:text?)
- if blob_text_viewable?(blob)
- if diff_view == 'parallel'
= render "projects/diffs/parallel_view", diff_file: diff_file, project: project, blob: blob, index: i
......
......@@ -25,15 +25,18 @@ class EmailsOnPushWorker
:push
end
diff_refs = nil
compare = nil
reverse_compare = false
if action == :push
compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha)
diff_refs = [project.merge_base_commit(before_sha, after_sha), project.commit(after_sha)]
return false if compare.same
if compare.commits.empty?
compare = Gitlab::Git::Compare.new(project.repository.raw_repository, after_sha, before_sha)
diff_refs = [project.merge_base_commit(after_sha, before_sha), project.commit(before_sha)]
reverse_compare = true
......@@ -41,7 +44,7 @@ class EmailsOnPushWorker
end
end
recipients.split(" ").each do |recipient|
recipients.split.each do |recipient|
begin
Notify.repository_push_email(
project_id,
......@@ -51,6 +54,7 @@ class EmailsOnPushWorker
action: action,
compare: compare,
reverse_compare: reverse_compare,
diff_refs: diff_refs,
send_from_committer_email: send_from_committer_email,
disable_diffs: disable_diffs
).deliver_now
......
......@@ -49,6 +49,7 @@ module Gitlab
config.assets.precompile << "*.png"
config.assets.precompile << "print.css"
config.assets.precompile << "notify.css"
config.assets.precompile << "mailers/repository_push_email.css"
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
......
......@@ -49,6 +49,10 @@ module Gitlab
@opts[:compare]
end
def diff_refs
@opts[:diff_refs]
end
def compare_timeout
compare.timeout if compare
end
......
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