From 8801f084abb2fe44ea10755a14431cbfd6d1c5c4 Mon Sep 17 00:00:00 2001 From: Artem Yegorov Date: Mon, 14 Oct 2024 21:47:52 +0300 Subject: [PATCH] #380: add check for empty repositories in DoT --- Gemfile.lock | 2 +- .../dimensions-of-terrain.rb | 9 ++- test/judges/test-dimensions-of-terrain.rb | 55 ++++++++++++++++++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1c418a40..0fd7441e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,7 +66,7 @@ GEM net-http faraday-retry (2.2.1) faraday (~> 2.0) - fbe (0.0.78) + fbe (0.0.79) backtrace (~> 0) baza.rb (~> 0) decoor (~> 0) diff --git a/judges/dimensions-of-terrain/dimensions-of-terrain.rb b/judges/dimensions-of-terrain/dimensions-of-terrain.rb index aa9157cb..3809f005 100644 --- a/judges/dimensions-of-terrain/dimensions-of-terrain.rb +++ b/judges/dimensions-of-terrain/dimensions-of-terrain.rb @@ -82,14 +82,18 @@ # Total number of commits for all repos commits = 0 Fbe.unmask_repos.each do |repo| - commits += Fbe.github_graph.total_commits(*repo.split('/'), Fbe.octo.repository(repo)[:default_branch]) + repo_info = Fbe.octo.repository(repo) + next if repo_info[:size].zero? + commits += Fbe.github_graph.total_commits(*repo.split('/'), repo_info[:default_branch]) end f.total_commits = commits # Total number of files for all repos files = 0 Fbe.unmask_repos.each do |repo| - Fbe.octo.tree(repo, Fbe.octo.repository(repo)[:default_branch], recursive: true).then do |json| + repo_info = Fbe.octo.repository(repo) + next if repo_info[:size].zero? + Fbe.octo.tree(repo, repo_info[:default_branch], recursive: true).then do |json| files += json[:tree].count { |item| item[:type] == 'blob' } end end @@ -98,6 +102,7 @@ # Total number of unique contributors in all repos contributors = Set.new Fbe.unmask_repos.each do |repo| + next if Fbe.octo.repository(repo)[:size].zero? Fbe.octo.contributors(repo).each do |contributor| contributors << contributor[:id] end diff --git a/test/judges/test-dimensions-of-terrain.rb b/test/judges/test-dimensions-of-terrain.rb index c33dee27..378e7ebc 100644 --- a/test/judges/test-dimensions-of-terrain.rb +++ b/test/judges/test-dimensions-of-terrain.rb @@ -283,7 +283,8 @@ def test_total_issues_and_pull_requests def test_total_commits WebMock.disable_net_connect! fb = Factbase.new - load_it('dimensions-of-terrain', fb, Judges::Options.new({ 'repositories' => 'foo/foo', 'testing' => true })) + load_it('dimensions-of-terrain', fb, + Judges::Options.new({ 'repositories' => 'foo/foo,yegor256/empty-repo', 'testing' => true })) f = fb.query("(eq what 'dimensions-of-terrain')").each.to_a.first assert_equal(1484, f.total_commits) end @@ -305,10 +306,29 @@ def test_total_files default_branch: 'master' } ) + stub_github( + 'https://api.github.com/repos/yegor256/empty-repo', + body: { + name: 'yegor256', + full_name: 'yegor256/empty-repo', + private: false, + created_at: Time.parse('2024-07-10 20:35:25 UTC'), + updated_at: Time.parse('2024-09-22 07:23:36 UTC'), + pushed_at: Time.parse('2024-09-22 20:22:51 UTC'), + size: 0, + stargazers_count: 0, + forks: 0, + default_branch: 'master' + } + ) stub_github( 'https://api.github.com/repos/foo/foo/releases?per_page=100', body: [] ) + stub_github( + 'https://api.github.com/repos/yegor256/empty-repo/releases?per_page=100', + body: [] + ) stub_github( 'https://api.github.com/repos/foo/foo/git/trees/master?recursive=true', body: { @@ -384,10 +404,15 @@ def test_total_files 'https://api.github.com/search/commits?per_page=100&q=repo:foo/foo%20author-date:%3E2024-08-30', body: { total_count: 0, incomplete_results: false, items: [] } ) + stub_github( + 'https://api.github.com/search/commits?per_page=100&q=repo:yegor256/empty-repo%20author-date:%3E2024-08-30', + body: { total_count: 0, incomplete_results: false, items: [] } + ) fb = Factbase.new Fbe.stub(:github_graph, Fbe::Graph::Fake.new) do Time.stub(:now, Time.parse('2024-09-29 21:00:00 UTC')) do - load_it('dimensions-of-terrain', fb) + load_it('dimensions-of-terrain', fb, + Judges::Options.new({ 'repositories' => 'foo/foo,yegor256/empty-repo' })) f = fb.query("(eq what 'dimensions-of-terrain')").each.to_a.first assert_equal(7, f.total_files) end @@ -411,10 +436,29 @@ def test_total_contributors default_branch: 'master' } ) + stub_github( + 'https://api.github.com/repos/yegor256/empty-repo', + body: { + name: 'yegor256', + full_name: 'yegor256/empty-repo', + private: false, + created_at: Time.parse('2024-07-10 20:35:25 UTC'), + updated_at: Time.parse('2024-09-22 07:23:36 UTC'), + pushed_at: Time.parse('2024-09-22 20:22:51 UTC'), + size: 0, + stargazers_count: 0, + forks: 0, + default_branch: 'master' + } + ) stub_github( 'https://api.github.com/repos/foo/foo/releases?per_page=100', body: [] ) + stub_github( + 'https://api.github.com/repos/yegor256/empty-repo/releases?per_page=100', + body: [] + ) stub_github( 'https://api.github.com/repos/foo/foo/git/trees/master?recursive=true', body: { sha: 'abc012345f', tree: [], truncated: false } @@ -440,10 +484,15 @@ def test_total_contributors 'https://api.github.com/search/commits?per_page=100&q=repo:foo/foo%20author-date:%3E2024-08-30', body: { total_count: 0, incomplete_results: false, items: [] } ) + stub_github( + 'https://api.github.com/search/commits?per_page=100&q=repo:yegor256/empty-repo%20author-date:%3E2024-08-30', + body: { total_count: 0, incomplete_results: false, items: [] } + ) fb = Factbase.new Fbe.stub(:github_graph, Fbe::Graph::Fake.new) do Time.stub(:now, Time.parse('2024-09-29 21:00:00 UTC')) do - load_it('dimensions-of-terrain', fb) + load_it('dimensions-of-terrain', fb, + Judges::Options.new({ 'repositories' => 'foo/foo,yegor256/empty-repo' })) f = fb.query("(eq what 'dimensions-of-terrain')").each.to_a.first assert_equal(12, f.total_contributors) end