Skip to content

Commit

Permalink
Add lowest_prerelease_suffix method (#10832)
Browse files Browse the repository at this point in the history
* Add lowest_prerelease_suffix method

* Apply change to python
  • Loading branch information
amazimbe authored Oct 23, 2024
1 parent eb77cb3 commit 8afbd08
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
9 changes: 7 additions & 2 deletions common/lib/dependabot/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')}"
Expand All @@ -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
8 changes: 8 additions & 0 deletions common/spec/dependabot/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
13 changes: 9 additions & 4 deletions maven/lib/dependabot/maven/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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('.')}"

Expand All @@ -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('.')}"

Expand All @@ -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]
Expand Down
8 changes: 8 additions & 0 deletions maven/spec/dependabot/maven/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
5 changes: 5 additions & 0 deletions python/lib/dependabot/python/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
8 changes: 8 additions & 0 deletions python/spec/dependabot/python/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down

0 comments on commit 8afbd08

Please sign in to comment.