Skip to content

Commit

Permalink
#192: calculate average reviewers per pr
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegorov committed Sep 9, 2024
1 parent e8c219e commit 566fd6b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 11 deletions.
8 changes: 6 additions & 2 deletions judges/quality-of-service/quality-of-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,22 @@
f.average_pull_hoc_size = hocs.empty? ? 0 : hocs.sum.to_f / hocs.size
f.average_pull_files_size = files.empty? ? 0 : files.sum.to_f / files.size

# Average review time and comments
# Average review time, comments and reviewers
review_times = []
review_comments = []
reviewers = []
Fbe.unmask_repos.each do |repo|
Fbe.octo.search_issues(
"repo:#{repo} type:pr is:merged closed:>#{f.since.utc.iso8601[0..9]}"
)[:items].each do |pr|
review = Fbe.octo.pull_request_reviews(repo, pr[:number]).min_by { |r| r[:submitted_at] }
reviews = Fbe.octo.pull_request_reviews(repo, pr[:number])
review = reviews.min_by { |r| r[:submitted_at] }
review_times << (pr[:merged_at] - review[:submitted_at]).to_i if review
review_comments << Fbe.octo.review_comments(repo, pr[:number]).size
reviewers << reviews.map { |r| r.dig(:user, :id) }.uniq.size
end
end
f.average_review_time = review_times.empty? ? 0 : review_times.sum.to_f / review_times.size
f.average_review_size = review_comments.empty? ? 0 : review_comments.sum.to_f / review_comments.size
f.average_reviewers_per_pull = reviewers.empty? ? 0 : reviewers.sum.to_f / reviewers.size
end
1 change: 1 addition & 0 deletions judges/quality-of-service/simple-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ expected:
- /fb/f[average_pull_files_size != 0]
- /fb/f[average_review_time != 0]
- /fb/f[average_review_size != 0]
- /fb/f[average_reviewers_per_pull != 0]
91 changes: 82 additions & 9 deletions test/judges/test-quality-of-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def test_quality_of_service_average_hocs_and_files
end
end

def test_quality_of_service_average_review_time_and_comments
def test_quality_of_service_average_review_time_comments_and_reviewers
WebMock.disable_net_connect!
stub_github('https://api.github.com/repos/foo/foo', body: { id: 42, full_name: 'foo/foo' })
stub_github(
Expand Down Expand Up @@ -591,25 +591,97 @@ def test_quality_of_service_average_review_time_and_comments
'https://api.github.com/repos/foo/foo/pulls/12/reviews?per_page=100',
body: [
{
id: 22_449_328, body: 'Some text 3', state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR', submitted_at: Time.parse('2024-08-23 10:00:00 UTC')
id: 22_449_328,
body: 'Some text 3',
user: { login: 'yegor256', id: 526_301, type: 'User' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-23 10:00:00 UTC')
},
{
id: 22_449_327, body: 'Some text 2', state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR', submitted_at: Time.parse('2024-08-22 10:00:00 UTC')
id: 22_449_327,
body: 'Some text 2',
user: { login: 'yegor257', id: 526_302, type: 'User' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-22 10:00:00 UTC')
},
{
id: 22_449_326, body: 'Some text 1', state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR', submitted_at: Time.parse('2024-08-21 22:00:00 UTC')
id: 22_449_326,
body: 'Some text 1',
user: { login: 'yegor257', id: 526_302, type: 'User' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-21 22:00:00 UTC')
}
]
)
stub_github(
'https://api.github.com/repos/foo/foo/pulls/14/reviews?per_page=100',
body: [
{
id: 22_449_329, body: 'Some text 1', state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR', submitted_at: Time.parse('2024-08-23 15:30:00 UTC')
id: 22_449_329,
body: 'Some text 1',
user: { login: 'yegor257', id: 526_302, type: 'User' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-23 15:30:00 UTC')
},
{
id: 22_449_330,
body: 'Some text 2',
user: { login: 'rultor', id: 526_303, type: 'Bot' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-23 16:30:00 UTC')
},
{
id: 22_449_331,
body: 'Some text 3',
user: { login: 'yegor256', id: 526_301, type: 'User' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-23 17:30:00 UTC')
},
{
id: 22_449_335,
body: 'Some text 4',
user: { login: 'yegor256', id: 526_301, type: 'User' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-23 18:30:00 UTC')
},
{
id: 22_449_336,
body: 'Some text 5',
user: { login: 'rultor', id: 526_303, type: 'Bot' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-23 19:30:00 UTC')
},
{
id: 22_449_337,
body: 'Some text 6',
user: { login: 'yegor257', id: 526_302, type: 'User' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-23 20:30:00 UTC')
},
{
id: 22_449_338,
body: 'Some text 7',
user: { login: 'yegor256', id: 526_301, type: 'User' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-23 21:30:00 UTC')
},
{
id: 22_449_339,
body: 'Some text 8',
user: { login: 'yegor256', id: 526_301, type: 'User' },
state: 'CHANGES_REQUESTED',
author_association: 'CONTRIBUTOR',
submitted_at: Time.parse('2024-08-23 22:30:00 UTC')
}
]
)
Expand Down Expand Up @@ -758,6 +830,7 @@ def test_quality_of_service_average_review_time_and_comments
assert_equal(Time.parse('2024-08-09 21:00:00 UTC'), f.when)
assert_in_delta(431_100, f.average_review_time)
assert_in_delta(3.333, f.average_review_size)
assert_in_delta(1.666, f.average_reviewers_per_pull)
end
end

Expand Down

0 comments on commit 566fd6b

Please sign in to comment.