-
Notifications
You must be signed in to change notification settings - Fork 0
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
Include Ruby versions in health score calculation #5
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c6075f5
Add ruby versions module
lovro-bikic d3997f5
Fetch ruby versions if ruby is a dependency
lovro-bikic 5dfe92b
Add ruby to dependencies if available
lovro-bikic 707063c
Set default ruby priority to 10
lovro-bikic 6e440b5
Ensure only semver-compliant versions are selected
lovro-bikic 194797a
Refactor
lovro-bikic a12cf71
Refactor with an early return
lovro-bikic 9de7a17
Fix a regression
lovro-bikic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -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
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no
ruby
gem: https://rubygems.org/gems/ruby