-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Expand Centralized Ecosystem Format with Language Version Information for Bundler #10867
Changes from 7 commits
301a5af
348ac80
d4e36a1
ed0e35c
3338c7c
6a04f4c
1bfa067
4f5a06a
d0381d2
56904c0
7765d58
5948781
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
# frozen_string_literal: true | ||
|
||
require "parallel" | ||
require "dependabot/bundler/language" | ||
require "dependabot/bundler/package_manager" | ||
require "dependabot/dependency" | ||
require "dependabot/file_parsers" | ||
require "dependabot/file_parsers/base" | ||
|
@@ -37,7 +39,8 @@ | |
@ecosystem ||= T.let( | ||
Ecosystem.new( | ||
name: ECOSYSTEM, | ||
package_manager: package_manager | ||
package_manager: package_manager, | ||
language: language | ||
), | ||
T.nilable(Ecosystem) | ||
) | ||
|
@@ -47,7 +50,12 @@ | |
|
||
sig { returns(Ecosystem::VersionManager) } | ||
def package_manager | ||
PackageManager.new(bundler_version) | ||
PackageManager.new(bundler_raw_version) | ||
end | ||
|
||
sig { returns(Ecosystem::VersionManager) } | ||
def language | ||
Language.new(ruby_raw_version) | ||
end | ||
|
||
def check_external_code(dependencies) | ||
|
@@ -327,6 +335,51 @@ | |
.reject { |f| f.name == "gems.rb" } | ||
end | ||
|
||
sig { returns(String) } | ||
def bundler_raw_version | ||
return bundler_raw_version if defined?(@bundler_raw_version) | ||
|
||
package_manager = PackageManager.new(bundler_version) | ||
|
||
# If selected version is unsupported, we are going to throw unsupported error | ||
# So we shoudn't try to get the raw version | ||
return bundler_version if package_manager.unsupported? | ||
|
||
# read raw version directly from the ecosystem environment | ||
bundler_raw_version = SharedHelpers.in_a_temporary_repo_directory( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review Tip: When retrieving the full raw version of Bundler, note that if an unsupported Bundler version (e.g., |
||
base_directory, | ||
repo_contents_path | ||
) do | ||
write_temporary_dependency_files | ||
NativeHelpers.run_bundler_subprocess( | ||
function: "bundler_raw_version", | ||
args: {}, | ||
bundler_version: bundler_version, | ||
options: { timeout_per_operation_seconds: 10 } | ||
) | ||
end | ||
bundler_raw_version || ::Bundler::VERSION | ||
end | ||
|
||
sig { returns(String) } | ||
def ruby_raw_version | ||
return @ruby_raw_version if defined?(@ruby_raw_version) | ||
|
||
ruby_raw_version = SharedHelpers.in_a_temporary_repo_directory( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review Tip: We want to find the raw version for language directly from the ecosystem environment. |
||
base_directory, | ||
repo_contents_path | ||
) do | ||
write_temporary_dependency_files | ||
NativeHelpers.run_bundler_subprocess( | ||
function: "ruby_raw_version", | ||
args: {}, | ||
bundler_version: bundler_version, | ||
options: { timeout_per_operation_seconds: 10 } | ||
) | ||
end | ||
ruby_raw_version || RUBY_VERSION | ||
end | ||
|
||
sig { returns(String) } | ||
def bundler_version | ||
@bundler_version ||= Helpers.bundler_version(lockfile) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# typed: strong | ||
# frozen_string_literal: true | ||
|
||
require "sorbet-runtime" | ||
require "dependabot/bundler/version" | ||
require "dependabot/ecosystem" | ||
|
||
module Dependabot | ||
module Bundler | ||
LANGUAGE = "ruby" | ||
|
||
class Language < Dependabot::Ecosystem::VersionManager | ||
extend T::Sig | ||
|
||
sig { params(raw_version: String).void } | ||
def initialize(raw_version) | ||
super( | ||
LANGUAGE, | ||
Version.new(raw_version) | ||
) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# typed: false | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/bundler/language" | ||
require "dependabot/ecosystem" | ||
require "spec_helper" | ||
|
||
RSpec.describe Dependabot::Bundler::Language do | ||
let(:language) { described_class.new(version) } | ||
let(:version) { "3.0.0" } | ||
|
||
describe "#initialize" do | ||
context "when version is a String" do | ||
let(:version) { "3.0.0" } | ||
|
||
it "sets the version correctly" do | ||
expect(language.version).to eq(Dependabot::Bundler::Version.new(version)) | ||
end | ||
|
||
it "sets the name correctly" do | ||
expect(language.name).to eq(Dependabot::Bundler::LANGUAGE) | ||
end | ||
end | ||
|
||
context "when version is a Dependabot::Bundler::Version" do | ||
let(:version) { "3.0.0" } | ||
|
||
it "sets the version correctly" do | ||
expect(language.version).to eq(version) | ||
end | ||
|
||
it "sets the name correctly" do | ||
expect(language.name).to eq(Dependabot::Bundler::LANGUAGE) | ||
end | ||
end | ||
end | ||
|
||
describe "#unsupported?" do | ||
it "returns false by default as no specific support or deprecation for languages is currently defined" do | ||
expect(language.unsupported?).to be false | ||
end | ||
end | ||
|
||
describe "#deprecated?" do | ||
it "returns false by default as no specific deprecation for languages is currently defined" do | ||
expect(language.deprecated?).to be false | ||
end | ||
end | ||
end |
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.
Review Tip: If the package manager is unsupported, the language version may not be retrievable. Additionally, fetching the language version is unnecessary, as the process will raise an unsupported package manager error.