Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#191: calculate average review comments size for pr #329

Merged
merged 1 commit into from
Sep 8, 2024
Merged
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
5 changes: 4 additions & 1 deletion judges/quality-of-service/quality-of-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,18 @@
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
# Average review time and comments
review_times = []
review_comments = []
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] }
review_times << (pr[:merged_at] - review[:submitted_at]).to_i if review
review_comments << Fbe.octo.review_comments(repo, pr[:number]).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
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 @@ -49,3 +49,4 @@ expected:
- /fb/f[average_pull_hoc_size != 0]
- /fb/f[average_pull_files_size != 0]
- /fb/f[average_review_time != 0]
- /fb/f[average_review_size != 0]
143 changes: 142 additions & 1 deletion test/judges/test-quality-of-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def test_runs_when_run_duration_ms_is_nil
'https://api.github.com/repos/foo/foo/pulls/12/reviews?per_page=100',
body: [{ id: 22_449_326, submitted_at: Time.parse('2024-07-21 22:00:00 UTC') }]
)
stub_github('https://api.github.com/repos/foo/foo/pulls/12/comments?per_page=100', body: [])
fb = Factbase.new
Time.stub(:now, Time.parse('2024-08-12 21:00:00 UTC')) do
load_it('quality-of-service', fb)
Expand Down Expand Up @@ -176,6 +177,7 @@ def test_quality_of_service_average_issues
}
}]
)
stub_github('https://api.github.com/repos/foo/foo/pulls/12/comments?per_page=100', body: [])
fb = Factbase.new
f = fb.insert
f.what = 'pmp'
Expand Down Expand Up @@ -265,6 +267,7 @@ def test_quality_of_service_average_build_mttr
'https://api.github.com/repos/foo/foo/pulls/12/reviews?per_page=100',
body: [{ id: 22_449_326, submitted_at: Time.parse('2024-08-21 22:00:00 UTC') }]
)
stub_github('https://api.github.com/repos/foo/foo/pulls/12/comments?per_page=100', body: [])
fb = Factbase.new
f = fb.insert
f.what = 'pmp'
Expand Down Expand Up @@ -366,6 +369,7 @@ def test_quality_of_service_average_build_mttr_when_failure_several_times_in_a_r
'https://api.github.com/repos/foo/foo/pulls/12/reviews?per_page=100',
body: [{ id: 22_449_326, submitted_at: Time.parse('2024-08-21 22:00:00 UTC') }]
)
stub_github('https://api.github.com/repos/foo/foo/pulls/12/comments?per_page=100', body: [])
fb = Factbase.new
f = fb.insert
f.what = 'pmp'
Expand Down Expand Up @@ -497,6 +501,11 @@ def test_quality_of_service_average_hocs_and_files
stub_github('https://api.github.com/repos/foo/foo/pulls/16/reviews?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls/18/reviews?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls/20/reviews?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls/12/comments?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls/14/comments?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls/16/comments?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls/18/comments?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls/20/comments?per_page=100', body: [])
fb = Factbase.new
f = fb.insert
f.what = 'pmp'
Expand All @@ -513,7 +522,7 @@ def test_quality_of_service_average_hocs_and_files
end
end

def test_quality_of_service_average_review_time
def test_quality_of_service_average_review_time_and_comments
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 @@ -605,6 +614,137 @@ def test_quality_of_service_average_review_time
]
)
stub_github('https://api.github.com/repos/foo/foo/pulls/16/reviews?per_page=100', body: [])
stub_github(
'https://api.github.com/repos/foo/foo/pulls/12/comments?per_page=100',
body: [
{
pull_request_review_id: 22_687_249,
id: 17_361_949,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'yegor256', id: 526_301, type: 'User' },
body: 'Some comment 1',
created_at: Time.parse('2024-09-05 10:31:06 UTC'),
updated_at: Time.parse('2024-09-05 10:33:04 UTC'),
author_association: 'MEMBER'
},
{
pull_request_review_id: 22_687_503,
id: 17_361_950,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'Yegorov', id: 123_234_123, type: 'User' },
body: 'Some comment 2',
created_at: Time.parse('2024-09-05 11:40:00 UTC'),
updated_at: Time.parse('2024-09-05 11:41:05 UTC'),
author_association: 'CONTRIBUTOR'
},
{
pull_request_review_id: 22_687_543,
id: 17_361_955,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'Yegorov', id: 123_234_123, type: 'User' },
body: 'Some comment 3',
created_at: Time.parse('2024-09-05 15:55:07 UTC'),
updated_at: Time.parse('2024-09-05 15:55:07 UTC'),
author_association: 'CONTRIBUTOR'
},
{
pull_request_review_id: 22_687_563,
id: 17_361_960,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'Yegorov', id: 123_234_123, type: 'User' },
body: 'Some comment 4',
created_at: Time.parse('2024-09-05 16:40:00 UTC'),
updated_at: Time.parse('2024-09-05 16:41:05 UTC'),
author_association: 'CONTRIBUTOR'
},
{
pull_request_review_id: 22_687_573,
id: 17_361_970,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'Yegorov', id: 123_234_123, type: 'User' },
body: 'Some comment 5',
created_at: Time.parse('2024-09-05 17:55:07 UTC'),
updated_at: Time.parse('2024-09-05 17:55:07 UTC'),
author_association: 'CONTRIBUTOR'
}
]
)
stub_github('https://api.github.com/repos/foo/foo/pulls/14/comments?per_page=100', body: [])
stub_github(
'https://api.github.com/repos/foo/foo/pulls/16/comments?per_page=100',
body: [
{
pull_request_review_id: 22_687_505,
id: 17_371_800,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'yegor256', id: 526_301, type: 'User' },
body: 'Some comment 1',
created_at: Time.parse('2024-09-05 10:31:06 UTC'),
updated_at: Time.parse('2024-09-05 10:33:04 UTC'),
author_association: 'MEMBER'
},
{
pull_request_review_id: 22_687_607,
id: 17_371_810,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'Yegorov', id: 123_234_123, type: 'User' },
body: 'Some comment 2',
created_at: Time.parse('2024-09-05 11:40:00 UTC'),
updated_at: Time.parse('2024-09-05 11:41:05 UTC'),
author_association: 'CONTRIBUTOR'
},
{
pull_request_review_id: 22_687_617,
id: 17_371_820,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'Yegorov', id: 123_234_123, type: 'User' },
body: 'Some comment 3',
created_at: Time.parse('2024-09-05 12:40:00 UTC'),
updated_at: Time.parse('2024-09-05 12:41:05 UTC'),
author_association: 'CONTRIBUTOR'
},
{
pull_request_review_id: 22_687_627,
id: 17_371_820,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'Yegorov', id: 123_234_123, type: 'User' },
body: 'Some comment 4',
created_at: Time.parse('2024-09-05 13:40:00 UTC'),
updated_at: Time.parse('2024-09-05 13:41:05 UTC'),
author_association: 'CONTRIBUTOR'
},
{
pull_request_review_id: 22_687_637,
id: 17_371_830,
diff_hunk: "@@ -427,4 +481,107 @@ def example\n",
path: 'test/example.rb',
commit_id: '11e3a0dd2d1',
user: { login: 'Yegorov', id: 123_234_123, type: 'User' },
body: 'Some comment 5',
created_at: Time.parse('2024-09-05 14:40:00 UTC'),
updated_at: Time.parse('2024-09-05 14:41:05 UTC'),
author_association: 'CONTRIBUTOR'
}
]
)
fb = Factbase.new
f = fb.insert
f.what = 'pmp'
Expand All @@ -617,6 +757,7 @@ def test_quality_of_service_average_review_time
assert_equal(Time.parse('2024-08-02 21:00:00 UTC'), f.since)
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)
end
end

Expand Down