Skip to content
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

Revert "Revert "Use new implementation of Maven version standard"" #10704

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 3 additions & 37 deletions common/lib/dependabot/config/ignore_condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,54 +57,20 @@ def versions_by_type(dependency)
version = correct_version_for(dependency)
return [] unless version

semver = version.to_semver

transformed_update_types.flat_map do |t|
case t
when PATCH_VERSION_TYPE
ignore_patch(semver)
version.ignored_patch_versions
when MINOR_VERSION_TYPE
ignore_minor(semver)
version.ignored_minor_versions
when MAJOR_VERSION_TYPE
ignore_major(semver)
version.ignored_major_versions
else
[]
end
end.compact
end

sig { params(version: String).returns(T::Array[String]) }
def ignore_patch(version)
parts = version.split(".")
version_parts = parts.fill("0", parts.length...2)
upper_parts = version_parts.first(1) + [version_parts[1].to_i + 1]
lower_bound = "> #{version}"
upper_bound = "< #{upper_parts.join('.')}"

["#{lower_bound}, #{upper_bound}"]
end

sig { params(version: String).returns(T::Array[String]) }
def ignore_minor(version)
parts = version.split(".")
version_parts = parts.fill("0", parts.length...2)
lower_parts = version_parts.first(1) + [version_parts[1].to_i + 1] + ["a"]
upper_parts = version_parts.first(0) + [version_parts[0].to_i + 1]
lower_bound = ">= #{lower_parts.join('.')}"
upper_bound = "< #{upper_parts.join('.')}"

["#{lower_bound}, #{upper_bound}"]
end

sig { params(version: String).returns(T::Array[String]) }
def ignore_major(version)
version_parts = version.split(".")
lower_parts = [version_parts[0].to_i + 1] + ["a"]
lower_bound = ">= #{lower_parts.join('.')}"

[lower_bound]
end

sig { params(dependency: Dependency).returns(T.nilable(Version)) }
def correct_version_for(dependency)
version = dependency.version
Expand Down
32 changes: 32 additions & 0 deletions common/lib/dependabot/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,37 @@ def self.correct?(version)
def to_semver
@original_version
end

sig { overridable.returns(T::Array[String]) }
def ignored_patch_versions
parts = to_semver.split(".")
version_parts = parts.fill("0", parts.length...2)
upper_parts = version_parts.first(1) + [version_parts[1].to_i + 1]
lower_bound = "> #{to_semver}"
upper_bound = "< #{upper_parts.join('.')}"

["#{lower_bound}, #{upper_bound}"]
end

sig { overridable.returns(T::Array[String]) }
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"]
upper_parts = version_parts.first(0) + [version_parts[0].to_i + 1]
lower_bound = ">= #{lower_parts.join('.')}"
upper_bound = "< #{upper_parts.join('.')}"

["#{lower_bound}, #{upper_bound}"]
end

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_bound = ">= #{lower_parts.join('.')}"

[lower_bound]
end
end
end
33 changes: 33 additions & 0 deletions common/spec/dependabot/version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# typed: true
# frozen_string_literal: true

require "spec_helper"
require "dependabot/version"

RSpec.describe Dependabot::Version do
subject(:version) { described_class.new(version_string) }

describe "#ignored_major_versions" do
subject(:ignored_versions) { version.ignored_major_versions }

let(:version_string) { "1.2.3-alpha.1" }

it { is_expected.to eq([">= 2.a"]) }
end

describe "#ignored_minor_versions" do
subject(:ignored_versions) { version.ignored_minor_versions }

let(:version_string) { "1.2.3-alpha.1" }

it { is_expected.to eq([">= 1.3.a, < 2"]) }
end

describe "#ignored_patch_versions" do
subject(:ignored_versions) { version.ignored_patch_versions }

let(:version_string) { "1.2.3-alpha.1" }

it { is_expected.to eq(["> #{version_string}, < 1.3"]) }
end
end
71 changes: 0 additions & 71 deletions maven/lib/dependabot/maven/new_version.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ def updated_requirements
attr_reader :properties_to_update

def update_requirement(req_string)
if req_string.include?(".+")
update_dynamic_requirement(req_string)
else
# Since range requirements are excluded this must be exact
update_exact_requirement(req_string)
end
# Since range requirements are excluded this must be exact
update_exact_requirement(req_string)
end

def update_exact_requirement(req_string)
Expand All @@ -64,16 +60,6 @@ def update_exact_requirement(req_string)
req_string.gsub(old_version.to_s, latest_version.to_s)
end

# This is really only a Gradle thing, but Gradle relies on this
# RequirementsUpdater too
def update_dynamic_requirement(req_string)
precision = req_string.split(".").take_while { |s| s != "+" }.count

version_parts = latest_version.segments.first(precision)

version_parts.join(".") + ".+"
end

def version_class
Maven::Version
end
Expand Down
Loading
Loading