Make notes for merge requests include commit notes and add helpers

This commit is contained in:
Riyad Preukschas 2012-10-10 12:06:30 +02:00
parent dda852a0d5
commit 3f72af9994
4 changed files with 16 additions and 2 deletions

View file

@ -13,7 +13,7 @@ module Notes
when "issue" when "issue"
project.issues.find(target_id).notes.inc_author.fresh.limit(20) project.issues.find(target_id).notes.inc_author.fresh.limit(20)
when "merge_request" when "merge_request"
project.merge_requests.find(target_id).notes.inc_author.fresh.limit(20) project.merge_requests.find(target_id).mr_and_commit_notes.inc_author.fresh.limit(20)
when "snippet" when "snippet"
project.snippets.find(target_id).notes.fresh project.snippets.find(target_id).notes.fresh
when "wall" when "wall"

View file

@ -7,6 +7,11 @@ class NotesController < ProjectResourceController
def index def index
notes notes
if params[:target_type] == "merge_request"
@mixed_targets = true
@main_target_type = params[:target_type].camelize
end
respond_with(@notes) respond_with(@notes)
end end

View file

@ -7,6 +7,11 @@ module NotesHelper
params[:loading_new].present? params[:loading_new].present?
end end
# Helps to distinguish e.g. commit notes in mr notes list
def note_for_main_target?(note)
!@mixed_targets || @main_target_type == note.noteable_type
end
def note_vote_class(note) def note_vote_class(note)
if note.upvote? if note.upvote?
"vote upvote" "vote upvote"

View file

@ -49,7 +49,7 @@ class Note < ActiveRecord::Base
end end
def target def target
if noteable_type == "Commit" if commit?
project.commit(noteable_id) project.commit(noteable_id)
else else
noteable noteable
@ -82,6 +82,10 @@ class Note < ActiveRecord::Base
noteable_type == "Commit" noteable_type == "Commit"
end end
def line_note?
line_code.present?
end
def commit_author def commit_author
@commit_author ||= @commit_author ||=
project.users.find_by_email(target.author_email) || project.users.find_by_email(target.author_email) ||