Commit 3f72af9994554c66a51cdfb4302e48da0edd043a

Authored by Riyad Preukschas
1 parent dda852a0

Make notes for merge requests include commit notes and add helpers

app/contexts/notes/load_context.rb
... ... @@ -13,7 +13,7 @@ module Notes
13 13 when "issue"
14 14 project.issues.find(target_id).notes.inc_author.fresh.limit(20)
15 15 when "merge_request"
16   - project.merge_requests.find(target_id).notes.inc_author.fresh.limit(20)
  16 + project.merge_requests.find(target_id).mr_and_commit_notes.inc_author.fresh.limit(20)
17 17 when "snippet"
18 18 project.snippets.find(target_id).notes.fresh
19 19 when "wall"
... ...
app/controllers/notes_controller.rb
... ... @@ -7,6 +7,11 @@ class NotesController < ProjectResourceController
7 7  
8 8 def index
9 9 notes
  10 + if params[:target_type] == "merge_request"
  11 + @mixed_targets = true
  12 + @main_target_type = params[:target_type].camelize
  13 + end
  14 +
10 15 respond_with(@notes)
11 16 end
12 17  
... ...
app/helpers/notes_helper.rb
... ... @@ -7,6 +7,11 @@ module NotesHelper
7 7 params[:loading_new].present?
8 8 end
9 9  
  10 + # Helps to distinguish e.g. commit notes in mr notes list
  11 + def note_for_main_target?(note)
  12 + !@mixed_targets || @main_target_type == note.noteable_type
  13 + end
  14 +
10 15 def note_vote_class(note)
11 16 if note.upvote?
12 17 "vote upvote"
... ...
app/models/note.rb
... ... @@ -49,7 +49,7 @@ class Note < ActiveRecord::Base
49 49 end
50 50  
51 51 def target
52   - if noteable_type == "Commit"
  52 + if commit?
53 53 project.commit(noteable_id)
54 54 else
55 55 noteable
... ... @@ -82,6 +82,10 @@ class Note < ActiveRecord::Base
82 82 noteable_type == "Commit"
83 83 end
84 84  
  85 + def line_note?
  86 + line_code.present?
  87 + end
  88 +
85 89 def commit_author
86 90 @commit_author ||=
87 91 project.users.find_by_email(target.author_email) ||
... ...