Skip to content

Commit 1c455aa

Browse files
author
Bamboo
committed
Merge pull request #80 from xystushi/fix_comments_count
[Review] Request from 'xystushi' @ 'xystushi/git-review/fix_comments_count'
2 parents 277b4d4 + 2bf6666 commit 1c455aa

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

lib/git-review/commands.rb

+18-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ def list(reverse=false)
1212
# explicitly look for local changes Github does not yet know about
1313
local.merged?(request.head.sha)
1414
}
15-
requests.reverse! if reverse
1615
source = local.source
1716
if requests.empty?
1817
puts "No pending requests for '#{source}'."
1918
else
2019
puts "Pending requests for '#{source}':"
2120
puts "ID Updated Comments Title"
22-
requests.each { |request| print_request(request) }
21+
print_requests(requests, reverse)
2322
end
2423
end
2524

@@ -173,18 +172,31 @@ def console
173172

174173
private
175174

176-
def print_request(request)
175+
def request_summary_line(request)
177176
date_string = format_time(request.updated_at)
178-
comments_count = request.comments.to_i + request.review_comments.to_i
177+
comments_count = github.comments_count(request)
179178
line = format_text(request.number, 8)
180179
line << format_text(date_string, 11)
181180
line << format_text(comments_count, 10)
182181
line << format_text(request.title, 91)
183-
puts line
182+
line
183+
end
184+
185+
def print_requests(requests, reverse=false)
186+
# put all output lines in a hash first, keyed by request number
187+
# this is to make sure the order is still correct even if we use
188+
# multi-threading to retrieve the requests
189+
output = {}
190+
requests.each { |req| output[req.number] = request_summary_line(req) }
191+
numbers = output.keys.sort
192+
numbers.reverse! if reverse
193+
numbers.each do |n|
194+
puts output[n]
195+
end
184196
end
185197

186198
def print_request_details(request)
187-
comments_count = request.comments.to_i + request.review_comments.to_i
199+
comments_count = github.comments_count(request)
188200
puts 'ID : ' + request.number.to_s
189201
puts 'Label : ' + request.head.label
190202
puts 'Updated : ' + format_time(request.updated_at)

lib/git-review/github.rb

+19-4
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,15 @@ def current_requests(repo=source_repo)
7171

7272
# a more detailed collection of requests
7373
def current_requests_full(repo=source_repo)
74-
@github.pull_requests(repo).collect { |request|
75-
@github.pull_request(repo, request.number)
76-
}
74+
threads = []
75+
requests = []
76+
@github.pull_requests(repo).each do |req|
77+
threads << Thread.new {
78+
requests << @github.pull_request(repo, req.number)
79+
}
80+
end
81+
threads.each { |t| t.join }
82+
requests
7783
end
7884

7985
def update
@@ -144,7 +150,8 @@ def commit_discussion(number)
144150
end
145151

146152
def issue_discussion(number)
147-
comments = @github.issue_comments(source_repo, number)
153+
comments = @github.issue_comments(source_repo, number) +
154+
@github.review_comments(source_repo, number)
148155
discussion = ["\nComments on pull request:\n\n"]
149156
discussion += comments.collect { |comment|
150157
name = comment.user.login
@@ -161,6 +168,14 @@ def issue_discussion(number)
161168
discussion.compact.flatten unless discussion.empty?
162169
end
163170

171+
# get the number of comments, including comments on commits
172+
def comments_count(request)
173+
issue_c = request.comments + request.review_comments
174+
commits_c = @github.pull_commits(source_repo, request.number).
175+
inject(0) { |sum, c| sum + c.commit.comment_count }
176+
issue_c + commits_c
177+
end
178+
164179
# show discussion for a request
165180
def discussion(number)
166181
commit_discussion(number) +

spec/git-review/commands_spec.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@
3333
it 'shows them' do
3434
subject.should_receive(:puts).with(/Pending requests for 'some_source'/)
3535
subject.should_not_receive(:puts).with(/No pending requests/)
36-
subject.should_receive(:print_request).with(req1).ordered
37-
subject.should_receive(:print_request).with(req2).ordered
36+
subject.should_receive(:print_requests).with([req1, req2], false)
3837
subject.list
3938
end
4039

4140
it 'sorts the output with --reverse option' do
4241
subject.stub(:puts)
43-
subject.should_receive(:print_request).with(req2).ordered
44-
subject.should_receive(:print_request).with(req1).ordered
42+
subject.should_receive(:print_requests).with([req1, req2], true)
4543
subject.list(true)
4644
end
4745

0 commit comments

Comments
 (0)