Skip to content

Commit

Permalink
Merge pull request #389 from Yegorov/380
Browse files Browse the repository at this point in the history
#380: add check for empty repositories in DoT
  • Loading branch information
yegor256 authored Oct 15, 2024
2 parents 24c7c2e + 8801f08 commit 65d0572
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
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

0 comments on commit 65d0572

Please sign in to comment.