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

#380: add check for empty repositories in DoT #389

Merged
merged 1 commit into from
Oct 15, 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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions judges/dimensions-of-terrain/dimensions-of-terrain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
55 changes: 52 additions & 3 deletions test/judges/test-dimensions-of-terrain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: {
Expand Down Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -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
Expand Down