diff --git a/common/lib/dependabot/version.rb b/common/lib/dependabot/version.rb index e7b6a2d2de7..8474f80f36d 100644 --- a/common/lib/dependabot/version.rb +++ b/common/lib/dependabot/version.rb @@ -52,7 +52,7 @@ def ignored_patch_versions def ignored_minor_versions parts = to_semver.split(".") version_parts = parts.fill("0", parts.length...2) - lower_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + ["a"] + lower_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + [lowest_prerelease_suffix] upper_parts = version_parts.first(0) + [version_parts[0].to_i + 1] lower_bound = ">= #{lower_parts.join('.')}" upper_bound = "< #{upper_parts.join('.')}" @@ -63,10 +63,15 @@ def ignored_minor_versions sig { overridable.returns(T::Array[String]) } def ignored_major_versions version_parts = to_semver.split(".") - lower_parts = [version_parts[0].to_i + 1] + ["a"] + lower_parts = [version_parts[0].to_i + 1] + [lowest_prerelease_suffix] lower_bound = ">= #{lower_parts.join('.')}" [lower_bound] end + + sig { returns(String) } + def lowest_prerelease_suffix + "a" + end end end diff --git a/common/spec/dependabot/version_spec.rb b/common/spec/dependabot/version_spec.rb index 6a46334aed4..f653f9d585f 100644 --- a/common/spec/dependabot/version_spec.rb +++ b/common/spec/dependabot/version_spec.rb @@ -7,6 +7,14 @@ RSpec.describe Dependabot::Version do subject(:version) { described_class.new(version_string) } + describe "#lowest_prerelease_suffix" do + subject(:ignored_versions) { version.lowest_prerelease_suffix } + + let(:version_string) { "1.2.3-alpha.1" } + + it { is_expected.to eq "a" } + end + describe "#ignored_major_versions" do subject(:ignored_versions) { version.ignored_major_versions } diff --git a/maven/lib/dependabot/maven/version.rb b/maven/lib/dependabot/maven/version.rb index 92fbf8af496..39b16822e65 100644 --- a/maven/lib/dependabot/maven/version.rb +++ b/maven/lib/dependabot/maven/version.rb @@ -65,6 +65,11 @@ def prerelease? end end + sig { returns(String) } + def lowest_prerelease_suffix + "a0" + end + sig { params(other: VersionParameter).returns(Integer) } def <=>(other) other = Dependabot::Maven::Version.new(other.to_s) unless other.is_a? Dependabot::Maven::Version @@ -78,7 +83,7 @@ def ignored_patch_versions version_parts = parts.fill("0", parts.length...2) # the a0 is so we can get the next earliest prerelease patch version - upper_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + ["a0"] + upper_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + [lowest_prerelease_suffix] lower_bound = "> #{to_semver}" upper_bound = "< #{upper_parts.join('.')}" @@ -91,8 +96,8 @@ def ignored_minor_versions return [] if parts.empty? # for non-semver versions version_parts = parts.fill("0", parts.length...2) - lower_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + ["a0"] - upper_parts = version_parts.first(0) + [version_parts[0].to_i + 1] + ["a0"] + lower_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + [lowest_prerelease_suffix] + upper_parts = version_parts.first(0) + [version_parts[0].to_i + 1] + [lowest_prerelease_suffix] lower_bound = ">= #{lower_parts.join('.')}" upper_bound = "< #{upper_parts.join('.')}" @@ -104,7 +109,7 @@ def ignored_major_versions version_parts = token_bucket.tokens # e.g [1,2,3] if version is 1.2.3-alpha3 return [] if version_parts.empty? # for non-semver versions - lower_parts = [version_parts[0].to_i + 1] + ["a0"] # earliest next major version prerelease + lower_parts = [version_parts[0].to_i + 1] + [lowest_prerelease_suffix] # earliest next major version prerelease lower_bound = ">= #{lower_parts.join('.')}" [lower_bound] diff --git a/maven/spec/dependabot/maven/version_spec.rb b/maven/spec/dependabot/maven/version_spec.rb index 821adec006d..83fec0ac3a5 100644 --- a/maven/spec/dependabot/maven/version_spec.rb +++ b/maven/spec/dependabot/maven/version_spec.rb @@ -559,6 +559,14 @@ it { is_expected.to eq(["> #{version_string}, < 1.3.a0"]) } end + describe "#lowest_prerelease_suffix" do + subject(:ignored_versions) { version.lowest_prerelease_suffix } + + let(:version_string) { "1.2.3-alpha.1" } + + it { is_expected.to eq "a0" } + end + describe "compatibility with Gem::Requirement" do subject { requirement.satisfied_by?(version) } diff --git a/python/lib/dependabot/python/version.rb b/python/lib/dependabot/python/version.rb index adbe980cf36..f619911f084 100644 --- a/python/lib/dependabot/python/version.rb +++ b/python/lib/dependabot/python/version.rb @@ -254,6 +254,11 @@ def dev_cmp_key T.must(dev) end + sig { returns(String) } + def lowest_prerelease_suffix + "dev0" + end + private sig { params(other: Dependabot::Python::Version).returns(Integer) } diff --git a/python/spec/dependabot/python/version_spec.rb b/python/spec/dependabot/python/version_spec.rb index 11f806cd9df..0895861b192 100644 --- a/python/spec/dependabot/python/version_spec.rb +++ b/python/spec/dependabot/python/version_spec.rb @@ -342,6 +342,14 @@ end end + describe "#lowest_prerelease_suffix" do + subject { version.lowest_prerelease_suffix } + + let(:version_string) { "1.2.3" } + + it { is_expected.to eq "dev0" } + end + describe "compatibility with Gem::Requirement" do subject { requirement.satisfied_by?(version) }