[refs #579] fixed commit comments errors
This commit is contained in:
parent
bb47567628
commit
c5d6707b8f
|
@ -9,15 +9,17 @@ class Projects::CommentsController < Projects::BaseController
|
|||
include CommentsHelper
|
||||
|
||||
def create
|
||||
anchor = ''
|
||||
if !set_additional_data
|
||||
flash[:error] = I18n.t("flash.comment.save_error")
|
||||
elsif @comment.save
|
||||
flash[:notice] = I18n.t("flash.comment.saved")
|
||||
anchor = view_context.comment_anchor(@comment)
|
||||
else
|
||||
flash[:error] = I18n.t("flash.comment.save_error")
|
||||
flash[:warning] = @comment.errors.full_messages.join('. ')
|
||||
end
|
||||
redirect_to project_commentable_path(@project, @commentable) + "#comment#{@comment.id}"
|
||||
redirect_to "#{project_commentable_path(@project, @commentable)}##{anchor}"
|
||||
end
|
||||
|
||||
def edit
|
||||
|
@ -91,7 +93,7 @@ class Projects::CommentsController < Projects::BaseController
|
|||
end
|
||||
@comment.data[:strings] = strings
|
||||
@comment.data[:view_path] = h(diff_path[0].renamed_file ? "#{diff_path[0].a_path.rtruncate 60} -> #{diff_path[0].b_path.rtruncate 60}" : diff_path[0].a_path.rtruncate(120))
|
||||
return true
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,11 +10,11 @@ class Projects::Git::CommitsController < Projects::Git::BaseController
|
|||
|
||||
def show
|
||||
@commit = @commentable = @project.repo.commit(params[:id])
|
||||
@comments = Comment.for_commit(@commit)
|
||||
@comments, @diff = Comment.for_commit(@commit), @commit.diffs
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.diff { render :text => (@commit.diffs.map(&:diff).join("\n") rescue ''), :content_type => "text/plain" }
|
||||
format.diff { render :text => (@diff.map(&:diff).join("\n") rescue ''), :content_type => "text/plain" }
|
||||
format.patch { render :text => (@commit.to_patch rescue ''), :content_type => "text/plain" }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,4 +17,8 @@ module CommentsHelper
|
|||
commit_path project, commentable.id
|
||||
end
|
||||
end
|
||||
|
||||
def comment_anchor c
|
||||
"#{(c.data.present? && c.actual_inline_comment?(@diff)) ? 'diff-' : ''}comment#{c.id}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -55,9 +55,13 @@ class Comment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def actual_inline_comment?(diff, force = false)
|
||||
return data[:actual] if data[:actual].present? && !force
|
||||
unless force
|
||||
return true if
|
||||
raise "This is not inline comment!" if data.blank? # for debug
|
||||
return data[:actual] if data[:actual].present?
|
||||
end
|
||||
filepath, line_number = data[:path], data[:line]
|
||||
diff_path = diff.select {|d| d.a_path == data[:path]}
|
||||
diff_path = (diff || commentable.diffs ).select {|d| d.a_path == data[:path]}
|
||||
comment_line = data[:line].to_i
|
||||
# NB! also dont create a comment to the diff header
|
||||
return data[:actual] = false if diff_path.blank? || comment_line == 0
|
||||
|
@ -77,13 +81,15 @@ class Comment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def inline_diff(repo)
|
||||
text = data[:strings]
|
||||
Rails.logger.debug "Comment id is #{id}; text class is #{text.class.name}; text is #{text}"
|
||||
closest = []
|
||||
text, closest = data[:strings], []
|
||||
(-2..0).each {|shift| closest << data["line#{shift}"]}
|
||||
text << closest.join("\n")
|
||||
end
|
||||
|
||||
def pull_comment?
|
||||
return true if commentable.class == Issue && commentable.pull_request.present?
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def subscribe_on_reply
|
||||
|
|
|
@ -13,6 +13,6 @@
|
|||
|
||||
-begin
|
||||
= render_commit_stats(stats)
|
||||
= render :partial => 'commit_diff', :collection => @commit.diffs
|
||||
= render :partial => 'commit_diff', :collection => @diff
|
||||
- rescue Grit::Git::GitTimeout
|
||||
%p= t 'layout.git.repositories.commit_diff_too_big'
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
= render 'projects/comments/comment', :comment => comment, :data => {:project => @project, :commentable => @issue}
|
||||
-else
|
||||
-comment = item[1].first
|
||||
-anchor = "#{comment.actual_inline_comment?(@diff) ? 'diff-' : ''}comment#{comment.id}"
|
||||
.file
|
||||
.top
|
||||
.l=comment.data[:view_path]
|
||||
.r=link_to t("layout.pull_requests.view_full_changes"),
|
||||
"#{project_commentable_path(@project, @commentable)}##{anchor}",
|
||||
"#{project_commentable_path(@project, @commentable)}##{comment_anchor(comment)}",
|
||||
:class => 'link_to_full_changes'
|
||||
.clear
|
||||
.diff_data=render_diff(comment.inline_diff(@repo), 0, item[1], comment.data[:path])
|
||||
|
|
Loading…
Reference in New Issue