display patch description (subject and body) from "git format-patch" files

This commit is contained in:
Frédéric Péters 2015-04-18 23:54:39 +02:00
parent 7b9889abe7
commit 5c8c4432fb
3 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,23 @@
<h2><%=h @attachment.filename %></h2>
<div class="attachments">
<p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %>
<span class="author"><%= link_to_user(@attachment.author) %>, <%= format_time(@attachment.created_on) %></span></p>
<p><%= link_to_attachment @attachment, :text => l(:button_download), :download => true -%>
<span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p>
</div>
<%= form_tag({}, :method => 'get') do %>
<p>
<%= l(:label_view_diff) %>:
<label><%= radio_button_tag 'type', 'inline', @diff_type != 'sbs', :onchange => "this.form.submit()" %> <%= l(:label_diff_inline) %></label>
<label><%= radio_button_tag 'type', 'sbs', @diff_type == 'sbs', :onchange => "this.form.submit()" %> <%= l(:label_diff_side_by_side) %></label>
</p>
<pre class="format-patch-description"><%= @diff_format_patch %></pre>
<% end %>
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type, :diff_style => nil} %>
<% html_title @attachment.filename %>
<% content_for :header_tags do -%>
<%= stylesheet_link_tag "scm" -%>
<% end -%>

View File

@ -3,6 +3,7 @@ require 'redmine'
require_dependency 'welcome_controller_patch'
require_dependency 'project_model_patch'
require_dependency 'mailer_patch'
require_dependency 'attachments_controller_patch'
Redmine::Plugin.register :redmine_entrouvert do
name 'Redmine Entr\'ouvert plugin'

View File

@ -0,0 +1,39 @@
module AttachmentsControllerPatch
def self.included(base)
base.class_eval do
def show
respond_to do |format|
format.html {
if @attachment.is_diff?
@diff = File.new(@attachment.diskfile, "rb").read
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
if (@diff.start_with?("From"))
@diff_format_patch = @diff.match(/(Subject.*)^---$/m)[0].sub(/^---$/m, '');
else
@diff_format_patch = nil;
end
# Save diff type as user preference
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
User.current.pref[:diff_type] = @diff_type
User.current.preference.save
end
render :action => 'diff'
elsif @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
@content = File.new(@attachment.diskfile, "rb").read
render :action => 'file'
else
download
end
}
format.api
end
end
end
end
end
# Add module to Attachments Controller
AttachmentsController.send(:include, AttachmentsControllerPatch)