Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion judges/code-was-reviewed/code-was-reviewed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
)
next
end
count = nil
reviews.each do |review|
next if review.dig(:user, :id) == pr.dig(:user, :id)
Fbe.fb.txn do |fbt|
Expand All @@ -89,7 +90,7 @@
n.when = review[:submitted_at]
n.hoc = pr[:additions] + pr[:deletions]
n.author = pr.dig(:user, :id)
n.comments =
count ||=
begin
Fbe.octo.issue_comments(repo, f.issue).count
rescue Octokit::NotFound, Octokit::Deprecated => e
Expand All @@ -110,6 +111,7 @@
)
0
end
n.comments = count
n.review_comments =
begin
Fbe.octo.pull_request_review_comments(repo, f.issue, review[:id]).count
Expand Down
30 changes: 30 additions & 0 deletions test/judges/test-code-was-reviewed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@ def test_find_absent_code_was_reviewed_facts
)
end

def test_fetches_issue_comments_once_for_multiple_reviews
WebMock.disable_net_connect!
rate_limit_up
stub_github('https://api.github.com/repositories/42', body: { id: 42, full_name: 'foo/foo' })
stub_github(
'https://api.github.com/repos/foo/foo/pulls/60',
body: {
id: 60, number: 60, user: { id: 421, login: 'user' },
created_at: Time.parse('2025-09-01 15:35:30 UTC'), additions: 1, deletions: 1
}
)
stub_github(
'https://api.github.com/repos/foo/foo/pulls/60/reviews?per_page=100',
body: [
{ id: 61_001, user: { id: 422, login: 'user2' }, submitted_at: Time.parse('2025-09-02 10:00:00 UTC') },
{ id: 61_002, user: { id: 423, login: 'user3' }, submitted_at: Time.parse('2025-09-02 11:00:00 UTC') }
]
)
stub = stub_github('https://api.github.com/repos/foo/foo/issues/60/comments?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls/60/reviews/61001/comments?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls/60/reviews/61002/comments?per_page=100', body: [])
stub_github('https://api.github.com/user/421', body: { id: 421, login: 'user1' })
stub_github('https://api.github.com/user/422', body: { id: 422, login: 'user2' })
stub_github('https://api.github.com/user/423', body: { id: 423, login: 'user3' })
fb = Factbase.new
fb.with(_id: 1, what: 'pull-was-closed', repository: 42, issue: 60, where: 'github')
load_it('code-was-reviewed', fb)
assert_requested(stub, times: 1)
end

def test_rescues_not_found_on_pull_request_lookup
WebMock.disable_net_connect!
rate_limit_up
Expand Down
Loading