From 117af44f4ea0d2b1c8bff0d60086c2dec0386c65 Mon Sep 17 00:00:00 2001 From: Artem Yegorov Date: Tue, 17 Sep 2024 22:09:22 +0300 Subject: [PATCH] #338: fix review times in QoS --- .../quality-of-service/quality-of-service.rb | 4 +- test/judges/test-quality-of-service.rb | 63 ++++++++++++++----- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/judges/quality-of-service/quality-of-service.rb b/judges/quality-of-service/quality-of-service.rb index d2ff70ee..9bddcaaa 100644 --- a/judges/quality-of-service/quality-of-service.rb +++ b/judges/quality-of-service/quality-of-service.rb @@ -155,8 +155,8 @@ "repo:#{repo} type:pr is:merged closed:>#{f.since.utc.iso8601[0..9]}" )[:items].each do |pr| pr_reviews = Fbe.octo.pull_request_reviews(repo, pr[:number]) - pr_review = pr_reviews.min_by { |r| r[:submitted_at] } - review_times << (pr[:merged_at] - pr_review[:submitted_at]).to_i if pr_review + pr_review = pr_reviews.select { |r| r[:submitted_at] }.min_by { |r| r[:submitted_at] } + review_times << (pr[:pull_request][:merged_at] - pr_review[:submitted_at]).to_i if pr_review review_comments << Fbe.octo.review_comments(repo, pr[:number]).size reviewers << pr_reviews.map { |r| r.dig(:user, :id) }.uniq.size reviews << pr_reviews.size diff --git a/test/judges/test-quality-of-service.rb b/test/judges/test-quality-of-service.rb index 47d4dbd3..90c8bee4 100644 --- a/test/judges/test-quality-of-service.rb +++ b/test/judges/test-quality-of-service.rb @@ -118,7 +118,10 @@ def test_runs_when_run_duration_ms_is_nil 'q=repo:foo/foo%20type:pr%20is:merged%20closed:%3E2024-07-15', body: { total_count: 1, incomplete_results: false, items: [ - { id: 50, number: 12, title: 'Awesome 12', merged_at: Time.parse('2024-08-23 18:30:00 UTC') } + { + id: 50, number: 12, title: 'Awesome 12', + pull_request: { merged_at: Time.parse('2024-08-23 18:30:00 UTC') } + } ] } ) @@ -600,11 +603,26 @@ def test_quality_of_service_average_hocs_and_files body: { total_count: 1, incomplete_results: false, items: [ - { id: 50, number: 12, title: 'Awesome 12', merged_at: Time.parse('2024-08-23 18:30:00 UTC') }, - { id: 52, number: 14, title: 'Awesome 14', merged_at: Time.parse('2024-08-23 18:30:00 UTC') }, - { id: 54, number: 16, title: 'Awesome 16', merged_at: Time.parse('2024-08-23 18:30:00 UTC') }, - { id: 56, number: 18, title: 'Awesome 18', merged_at: Time.parse('2024-08-23 18:30:00 UTC') }, - { id: 58, number: 20, title: 'Awesome 20', merged_at: Time.parse('2024-08-23 18:30:00 UTC') } + { + id: 50, number: 12, title: 'Awesome 12', + pull_request: { merged_at: Time.parse('2024-08-23 18:30:00 UTC') } + }, + { + id: 52, number: 14, title: 'Awesome 14', + pull_request: { merged_at: Time.parse('2024-08-23 18:30:00 UTC') } + }, + { + id: 54, number: 16, title: 'Awesome 16', + pull_request: { merged_at: Time.parse('2024-08-23 18:30:00 UTC') } + }, + { + id: 56, number: 18, title: 'Awesome 18', + pull_request: { merged_at: Time.parse('2024-08-23 18:30:00 UTC') } + }, + { + id: 58, number: 20, title: 'Awesome 20', + pull_request: { merged_at: Time.parse('2024-08-23 18:30:00 UTC') } + } ] } ) @@ -739,12 +757,21 @@ def test_quality_of_service_average_review_time_comments_reviewers_and_reviews body: { total_count: 1, incomplete_results: false, items: [ - { id: 50, number: 12, title: 'Awesome 12', created_at: Time.parse('2024-08-20 22:00:00 UTC'), - merged_at: Time.parse('2024-08-27 18:30:00 UTC') }, - { id: 51, number: 14, title: 'Awesome 14', created_at: Time.parse('2024-08-23 12:00:00 UTC'), - merged_at: Time.parse('2024-08-27 18:30:00 UTC') }, - { id: 52, number: 16, title: 'Awesome 16', created_at: Time.parse('2024-08-25 12:00:00 UTC'), - merged_at: Time.parse('2024-08-27 18:30:00 UTC') } + { + id: 50, number: 12, title: 'Awesome 12', + created_at: Time.parse('2024-08-20 22:00:00 UTC'), + pull_request: { merged_at: Time.parse('2024-08-27 18:30:00 UTC') } + }, + { + id: 51, number: 14, title: 'Awesome 14', + created_at: Time.parse('2024-08-23 12:00:00 UTC'), + pull_request: { merged_at: Time.parse('2024-08-27 18:30:00 UTC') } + }, + { + id: 52, number: 16, title: 'Awesome 16', + created_at: Time.parse('2024-08-25 12:00:00 UTC'), + pull_request: { merged_at: Time.parse('2024-08-27 18:30:00 UTC') } + } ] } ) @@ -769,7 +796,7 @@ def test_quality_of_service_average_review_time_comments_reviewers_and_reviews 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') + submitted_at: nil }, { id: 22_449_327, @@ -805,8 +832,7 @@ def test_quality_of_service_average_review_time_comments_reviewers_and_reviews 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') + author_association: 'CONTRIBUTOR' }, { id: 22_449_331, @@ -1144,7 +1170,12 @@ def stub_workflow_runs(workflow_runs) 'q=repo:foo/foo%20type:pr%20is:merged%20closed:%3E2024-08-02', body: { total_count: 1, incomplete_results: false, - items: [{ id: 50, number: 12, title: 'Awesome 12', merged_at: Time.parse('2024-08-23 18:30:00 UTC') }] + items: [ + { + id: 50, number: 12, title: 'Awesome 12', + pull_request: { merged_at: Time.parse('2024-08-23 18:30:00 UTC') } + } + ] } ) stub_github(