Commit 3f72af9994554c66a51cdfb4302e48da0edd043a
1 parent
dda852a0
Exists in
master
and in
4 other branches
Make notes for merge requests include commit notes and add helpers
Showing
4 changed files
with
16 additions
and
2 deletions
Show diff stats
app/contexts/notes/load_context.rb
| @@ -13,7 +13,7 @@ module Notes | @@ -13,7 +13,7 @@ module Notes | ||
| 13 | when "issue" | 13 | when "issue" |
| 14 | project.issues.find(target_id).notes.inc_author.fresh.limit(20) | 14 | project.issues.find(target_id).notes.inc_author.fresh.limit(20) |
| 15 | when "merge_request" | 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 | when "snippet" | 17 | when "snippet" |
| 18 | project.snippets.find(target_id).notes.fresh | 18 | project.snippets.find(target_id).notes.fresh |
| 19 | when "wall" | 19 | when "wall" |
app/controllers/notes_controller.rb
| @@ -7,6 +7,11 @@ class NotesController < ProjectResourceController | @@ -7,6 +7,11 @@ class NotesController < ProjectResourceController | ||
| 7 | 7 | ||
| 8 | def index | 8 | def index |
| 9 | notes | 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 | respond_with(@notes) | 15 | respond_with(@notes) |
| 11 | end | 16 | end |
| 12 | 17 |
app/helpers/notes_helper.rb
| @@ -7,6 +7,11 @@ module NotesHelper | @@ -7,6 +7,11 @@ module NotesHelper | ||
| 7 | params[:loading_new].present? | 7 | params[:loading_new].present? |
| 8 | end | 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 | def note_vote_class(note) | 15 | def note_vote_class(note) |
| 11 | if note.upvote? | 16 | if note.upvote? |
| 12 | "vote upvote" | 17 | "vote upvote" |
app/models/note.rb
| @@ -49,7 +49,7 @@ class Note < ActiveRecord::Base | @@ -49,7 +49,7 @@ class Note < ActiveRecord::Base | ||
| 49 | end | 49 | end |
| 50 | 50 | ||
| 51 | def target | 51 | def target |
| 52 | - if noteable_type == "Commit" | 52 | + if commit? |
| 53 | project.commit(noteable_id) | 53 | project.commit(noteable_id) |
| 54 | else | 54 | else |
| 55 | noteable | 55 | noteable |
| @@ -82,6 +82,10 @@ class Note < ActiveRecord::Base | @@ -82,6 +82,10 @@ class Note < ActiveRecord::Base | ||
| 82 | noteable_type == "Commit" | 82 | noteable_type == "Commit" |
| 83 | end | 83 | end |
| 84 | 84 | ||
| 85 | + def line_note? | ||
| 86 | + line_code.present? | ||
| 87 | + end | ||
| 88 | + | ||
| 85 | def commit_author | 89 | def commit_author |
| 86 | @commit_author ||= | 90 | @commit_author ||= |
| 87 | project.users.find_by_email(target.author_email) || | 91 | project.users.find_by_email(target.author_email) || |