-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include Ruby versions in health score calculation (#5)
* Add ruby versions module * Fetch ruby versions if ruby is a dependency * Add ruby to dependencies if available * Set default ruby priority to 10 * Ensure only semver-compliant versions are selected * Refactor * Refactor with an early return * Fix a regression
- Loading branch information
1 parent
3083ab8
commit 9d9bd95
Showing
11 changed files
with
198 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'open-uri' | ||
|
||
module Polariscope | ||
module Scanner | ||
module RubyVersions | ||
VERSIONS_INDEX_FILE_URL = 'https://cache.ruby-lang.org/pub/ruby/index.txt' | ||
MINIMUM_RUBY_VERSION = Gem::Version.new('1.0.0') | ||
OPEN_TIMEOUT = 5 | ||
READ_TIMEOUT = 5 | ||
|
||
module_function | ||
|
||
def available_versions # rubocop:disable Metrics/AbcSize | ||
URI | ||
.parse(VERSIONS_INDEX_FILE_URL) | ||
.open(open_timeout: OPEN_TIMEOUT, read_timeout: READ_TIMEOUT, &:readlines) | ||
.drop(1) # header row | ||
.map { |line| line.split("\t").first.sub('ruby-', 'ruby ') } # ruby-2.3.4 -> ruby 2.3.4 | ||
.filter_map { |ruby_version| Bundler::RubyVersion.from_string(ruby_version)&.gem_version } | ||
.select { |gem_version| gem_version >= MINIMUM_RUBY_VERSION && gem_version.segments.size == 3 } | ||
.to_set | ||
rescue Timeout::Error | ||
Set.new | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,7 @@ DEPENDENCIES | |
rspec-rails (~> 5) | ||
shrine | ||
sidekiq (~> 6) | ||
tzinfo-data | ||
|
||
BUNDLED WITH | ||
2.5.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,7 +193,7 @@ DEPENDENCIES | |
sidekiq (~> 6) | ||
|
||
RUBY VERSION | ||
ruby 3.0.0p100 | ||
ruby 2.5.0p100 | ||
|
||
BUNDLED WITH | ||
2.5.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Polariscope::Scanner::RubyVersions do | ||
subject(:ruby_versions) { described_class } | ||
|
||
describe '.available_versions' do | ||
it 'returns published ruby versions' do | ||
result = ruby_versions.available_versions | ||
|
||
expect(result).to be_a(Set) | ||
expect(result.map(&:class).uniq).to contain_exactly(Gem::Version) | ||
expect(result.none?(&:prerelease?)).to be(true) | ||
expect(result.min).to eq(Gem::Version.new('1.2.1')) | ||
end | ||
|
||
context 'when an open timeout error is raised' do | ||
before { allow(URI).to receive(:parse).and_raise(Net::OpenTimeout) } | ||
|
||
it 'returns an empty set' do | ||
expect(ruby_versions.available_versions).to eq(Set.new) | ||
end | ||
end | ||
|
||
context 'when a read timeout error is raised' do | ||
before { allow(URI).to receive(:parse).and_raise(Net::ReadTimeout) } | ||
|
||
it 'returns an empty set' do | ||
expect(ruby_versions.available_versions).to eq(Set.new) | ||
end | ||
end | ||
end | ||
end |