Commit dda852a0d5c9e684b82cf20380d2b26da1798ecb

Authored by Dmitriy Zaporozhets
2 parents 60b4c88e 6dc8c0ea

Merge pull request #1629 from riyad/show-notes-indicator-for-commits-and-merge-requests

Show numer of notes for commits and merge requests
app/assets/stylesheets/sections/commits.scss
... ... @@ -203,6 +203,11 @@
203 203 @extend .cgray;
204 204 }
205 205  
  206 + .notes_count {
  207 + float:right;
  208 + margin: -6px 8px 6px;
  209 + }
  210 +
206 211 code {
207 212 background:#FCEEC1;
208 213 color:$style_color;
... ...
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
... ... @@ -9,7 +9,7 @@
9 9 - if merge_request.notes.any?
10 10 %span.btn.small.disabled.grouped
11 11 %i.icon-comment
12   - = merge_request.notes.count
  12 + = merge_request.mr_and_commit_notes.count
13 13 %span.btn.small.disabled.grouped
14 14 = merge_request.source_branch
15 15 →
... ...
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
... ...