Commit dda852a0d5c9e684b82cf20380d2b26da1798ecb
Exists in
master
and in
4 other branches
Merge pull request #1629 from riyad/show-notes-indicator-for-commits-and-merge-requests
Show numer of notes for commits and merge requests
Showing
5 changed files
with
33 additions
and
1 deletions
Show diff stats
app/assets/stylesheets/sections/commits.scss
app/models/merge_request.rb
| ... | ... | @@ -186,6 +186,11 @@ class MergeRequest < ActiveRecord::Base |
| 186 | 186 | |
| 187 | 187 | patch_path |
| 188 | 188 | end |
| 189 | + | |
| 190 | + def mr_and_commit_notes | |
| 191 | + commit_ids = commits.map(&:id) | |
| 192 | + Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND noteable_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids) | |
| 193 | + end | |
| 189 | 194 | end |
| 190 | 195 | |
| 191 | 196 | # == Schema Information | ... | ... |
app/views/commits/_commit.html.haml
| ... | ... | @@ -13,3 +13,10 @@ |
| 13 | 13 | = time_ago_in_words(commit.committed_date) |
| 14 | 14 | ago |
| 15 | 15 | |
| 16 | + | |
| 17 | + %span.notes_count | |
| 18 | + - notes = @project.commit_notes(commit) + @project.commit_line_notes(commit) | |
| 19 | + - if notes.any? | |
| 20 | + %span.btn.small.disabled.grouped | |
| 21 | + %i.icon-comment | |
| 22 | + = notes.count | ... | ... |
app/views/merge_requests/_merge_request.html.haml
spec/models/merge_request_spec.rb
| ... | ... | @@ -35,4 +35,19 @@ describe MergeRequest do |
| 35 | 35 | it { should include_module(IssueCommonality) } |
| 36 | 36 | it { should include_module(Votes) } |
| 37 | 37 | end |
| 38 | + | |
| 39 | + describe "#mr_and_commit_notes" do | |
| 40 | + let!(:merge_request) { Factory.create(:merge_request) } | |
| 41 | + | |
| 42 | + before do | |
| 43 | + merge_request.stub(:commits) { [merge_request.project.commit] } | |
| 44 | + Factory.create(:note, noteable: merge_request.commits.first) | |
| 45 | + Factory.create(:note, noteable: merge_request) | |
| 46 | + end | |
| 47 | + | |
| 48 | + it "should include notes for commits" do | |
| 49 | + merge_request.commits.should_not be_empty | |
| 50 | + merge_request.mr_and_commit_notes.count.should == 2 | |
| 51 | + end | |
| 52 | + end | |
| 38 | 53 | end | ... | ... |