Skip to content

Commit

Permalink
#412: three moved
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 18, 2024
1 parent ecbc1b4 commit 7946e01
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 51 deletions.
53 changes: 29 additions & 24 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.2.1)
activesupport (8.0.1)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
Expand All @@ -12,6 +13,7 @@ GEM
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ansi (1.5.0)
Expand All @@ -30,6 +32,7 @@ GEM
retries (~> 0)
tago (~> 0)
typhoeus (~> 1.3)
benchmark (0.4.0)
bigdecimal (3.1.8)
builder (3.3.0)
concurrent-ruby (1.3.4)
Expand All @@ -54,16 +57,16 @@ GEM
others (> 0)
tago (> 0)
yaml (~> 0.3)
faraday (2.12.0)
faraday-net_http (>= 2.0, < 3.4)
faraday (2.12.2)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-http-cache (2.5.1)
faraday (>= 0.8)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (3.3.0)
net-http
faraday-multipart (1.1.0)
multipart-post (~> 2.0)
faraday-net_http (3.4.0)
net-http (>= 0.5.0)
faraday-retry (2.2.1)
faraday (~> 2.0)
fbe (0.0.79)
Expand All @@ -86,18 +89,18 @@ GEM
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
fiber-storage (1.0.0)
gli (2.21.5)
graphql (2.3.18)
gli (2.22.0)
graphql (2.4.8)
base64
fiber-storage
graphql-client (0.23.0)
graphql-client (0.25.0)
activesupport (>= 3.0)
graphql (>= 1.13.0)
hashdiff (1.1.1)
hashdiff (1.1.2)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
iri (0.8.0)
json (2.8.2)
json (2.9.0)
judges (0.27.0)
backtrace (~> 0)
baza.rb (~> 0)
Expand All @@ -115,7 +118,7 @@ GEM
typhoeus (~> 1.3)
language_server-protocol (3.17.0.3)
liquid (5.5.1)
logger (1.6.1)
logger (1.6.3)
loog (0.6.0)
minitest (5.25.4)
minitest-reporters (1.7.1)
Expand All @@ -125,14 +128,14 @@ GEM
ruby-progressbar
moments (0.3.0)
multipart-post (2.4.1)
net-http (0.4.1)
net-http (0.6.0)
uri
nokogiri (1.16.7-arm64-darwin)
nokogiri (1.17.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
nokogiri (1.17.2-x86_64-linux)
racc (~> 1.4)
obk (0.3.1)
octokit (9.1.0)
octokit (9.2.0)
faraday (>= 1, < 3)
sawyer (~> 0.9)
others (0.0.3)
Expand All @@ -146,7 +149,7 @@ GEM
rake (13.2.1)
regexp_parser (2.9.3)
retries (0.0.5)
rexml (3.3.8)
rexml (3.4.0)
rubocop (1.69.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
Expand All @@ -157,37 +160,39 @@ GEM
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.2)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
securerandom (0.3.1)
securerandom (0.4.1)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-cobertura (2.1.0)
rexml
simplecov (~> 0.19)
simplecov-html (0.12.3)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
tago (0.0.2)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
uri (0.13.1)
unicode-display_width (3.1.2)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
uri (1.0.2)
verbose (0.0.2)
loog (~> 0.2)
tago (~> 0.0)
webmock (3.24.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
yaml (0.3.0)
yaml (0.4.0)

PLATFORMS
arm64-darwin-22
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ In order to run "live" tests of some judges, do this:
bundle exec rake -- --live
```

In order to run a single test, try this:

```bash
bundle exec ruby test/judges/test-dimensions-of-terrain.rb -n test_total_repositories
```

[factbase]: https://github.com/yegor256/factbase
[secrets]: https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions
[ours]: https://github.com/zerocracy/judges-action/blob/master/.github/workflows/zerocracy.yml
33 changes: 8 additions & 25 deletions judges/dimensions-of-terrain/dimensions-of-terrain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,16 @@
f.what = $judge
f.when = Time.now

# Total number of repositories in the project:
total = 0
Fbe.unmask_repos.each do |repo|
total += 1 unless Fbe.octo.repository(repo)[:archived]
end
f.total_repositories = total

# Total number of releases ever made:
total = 0
Fbe.unmask_repos.each do |repo|
Fbe.octo.releases(repo).each do |_|
total += 1
end
end
f.total_releases = total

# Total number of stars and forks for all repos:
stars = 0
forks = 0
Fbe.unmask_repos.each do |repo|
Fbe.octo.repository(repo).then do |json|
stars += json[:stargazers_count]
forks += json[:forks]
Dir[File.join(__dir__, 'total_*.rb')].each do |rb|
n = File.basename(rb).gsub(/\.rb$/, '')
next unless f[n].nil?
if Fbe.octo.off_quota
$loog.info('No GitHub quota left, it is time to stop')
break
end
require_relative rb
send(n).each { |k, v| f.send("#{k}=", v) }
end
f.total_stars = stars
f.total_forks = forks

# Total number of issues and pull requests for all repos
issues = 0
Expand Down
41 changes: 41 additions & 0 deletions judges/dimensions-of-terrain/total_releases.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'fbe/octo'
require 'fbe/unmask_repos'

# Total number of releases ever made:
#
# This function is called from the "dimensions-of-terrain.rb".
#
# @return Hash Map with keys as fact attributes and values as integers
def total_releases
total = 0
Fbe.unmask_repos.each do |repo|
Fbe.octo.releases(repo).each do |_|
total += 1
end
end
{ total_releases: total }
end
39 changes: 39 additions & 0 deletions judges/dimensions-of-terrain/total_repositories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'fbe/octo'
require 'fbe/unmask_repos'

# Total number of repositories in the project.
#
# This function is called from the "dimensions-of-terrain.rb".
#
# @return Hash Map with keys as fact attributes and values as integers
def total_repositories
total = 0
Fbe.unmask_repos.each do |repo|
total += 1 unless Fbe.octo.repository(repo)[:archived]
end
{ total_repositories: total }
end
43 changes: 43 additions & 0 deletions judges/dimensions-of-terrain/total_stars.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'fbe/octo'
require 'fbe/unmask_repos'

# Total number of stars and forks for all repos:
#
# This function is called from the "dimensions-of-terrain.rb".
#
# @return Hash Map with keys as fact attributes and values as integers
def total_stars
stars = 0
forks = 0
Fbe.unmask_repos.each do |repo|
Fbe.octo.repository(repo).then do |json|
stars += json[:stargazers_count]
forks += json[:forks]
end
end
{ total_stars: stars, total_forks: forks }
end
9 changes: 9 additions & 0 deletions test/judges/test-dimensions-of-terrain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
# SOFTWARE.

require 'factbase'
require 'fbe/octo'
require 'fbe/github_graph'
require 'loog'
require 'json'
require 'minitest/autorun'
require 'webmock/minitest'
require 'judges/options'
require_relative '../test__helper'

# Test.
class TestDimensionsOfTerrain < Minitest::Test
def test_total_repositories
WebMock.disable_net_connect!
stub_github('https://api.github.com/rate_limit', body: {})
stub_github(
'https://api.github.com/repos/foo/foo',
body: {
Expand Down Expand Up @@ -152,6 +156,7 @@ def test_total_repositories

def test_total_releases
WebMock.disable_net_connect!
stub_github('https://api.github.com/rate_limit', body: {})
stub_github(
'https://api.github.com/repos/foo/foo',
body: {
Expand Down Expand Up @@ -203,6 +208,7 @@ def test_total_releases

def test_total_stars_and_forks
WebMock.disable_net_connect!
stub_github('https://api.github.com/rate_limit', body: {})
stub_github(
'https://api.github.com/repos/foo/foo',
body: {
Expand Down Expand Up @@ -291,6 +297,7 @@ def test_total_commits

def test_total_files
WebMock.disable_net_connect!
stub_github('https://api.github.com/rate_limit', body: {})
stub_github(
'https://api.github.com/repos/foo/foo',
body: {
Expand Down Expand Up @@ -421,6 +428,7 @@ def test_total_files

def test_total_contributors
WebMock.disable_net_connect!
stub_github('https://api.github.com/rate_limit', body: {})
stub_github(
'https://api.github.com/repos/foo/foo',
body: {
Expand Down Expand Up @@ -501,6 +509,7 @@ def test_total_contributors

def test_total_active_contributors
WebMock.disable_net_connect!
stub_github('https://api.github.com/rate_limit', body: {})
stub_github(
'https://api.github.com/repos/foo/foo',
body: {
Expand Down
Loading

0 comments on commit 7946e01

Please sign in to comment.