Skip to content

Commit e36d11b

Browse files
committed
Jenkin plugin versions should be comparable
1 parent 47fb9cd commit e36d11b

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

maven/lib/dependabot/maven/shared/shared_version_finder.rb

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,40 @@ def matches_dependency_version_type?(comparison_version)
6868
current_suffix = extract_version_suffix(current_version_string)
6969
candidate_suffix = extract_version_suffix(candidate_version_string)
7070

71+
return true if contains_git_sha?(current_suffix) && contains_git_sha?(candidate_suffix)
72+
7173
# If both versions share the exact suffix or no suffix, they are compatible
7274
current_suffix == candidate_suffix
7375
end
7476

77+
GIT_COMMIT = /\A[0-9a-f]{7,40}\z/i.freeze
78+
79+
def git_sha?(version)
80+
return false unless version
81+
82+
return true if version.match?(GIT_COMMIT)
83+
84+
# Strip leading v if any and try again (e.g., v018aa6b0d3)
85+
version = version[1..-1] if version.start_with?('v')
86+
87+
version.match?(GIT_COMMIT)
88+
end
89+
90+
sig { params(version: T.nilable(String)).returns(T::Boolean) }
91+
def contains_git_sha?(version)
92+
return false unless version
93+
94+
# Split by common delimiters
95+
split = version.split(/[-._]/)
96+
97+
# Return true if any part is a commit
98+
return true if split.any? { |part| git_sha?(part) }
99+
100+
# Matches if the entire suffix is a commit
101+
# Example: va_b_018a_a_6b_0d3
102+
git_sha?(split.join)
103+
end
104+
75105
private
76106

77107
# Extracts the qualifier/suffix from a Maven version string.
@@ -100,8 +130,7 @@ def extract_version_suffix(version_string)
100130
# e.g., "1.0.0-1" or "1.0.0_2" are not considered to have a meaningful suffix
101131
return nil if suffix.match?(/^_?\d+$/)
102132

103-
# Must contain a hyphen to be considered a valid suffix
104-
return suffix if suffix.include?("-") || suffix.include?("_")
133+
return suffix if suffix.include?("-") || suffix.include?("_") || git_sha?(suffix)
105134
end
106135

107136
nil

maven/spec/dependabot/maven/shared/shared_version_finder_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,58 @@
400400
end
401401
end
402402
end
403+
404+
context "when the dependency uses Jenkin's plugin release conventions" do
405+
# See
406+
# https://www.jenkins.io/doc/developer/publishing/releasing-cd/
407+
# https://github.com/jenkinsci/jep/blob/master/jep/305/README.adoc
408+
409+
context "when the version contains embedded git commits" do
410+
let(:dependency_version) { "5933.vcf06f7b_5d1a_2" }
411+
let(:comparison_version) { "5857.vb_f3dd0731f44" }
412+
it { is_expected.to be true }
413+
end
414+
415+
context "when the version has a single embedded git commit" do
416+
let(:dependency_version) { "5622.c9c3051619f5" }
417+
let(:comparison_version) { "5681.79d2ddf61465" }
418+
it { is_expected.to be true }
419+
end
420+
421+
context "when the version has a single embedded git commit using different delimiters" do
422+
let(:dependency_version) { "5622-c9c3051619f5" }
423+
let(:comparison_version) { "5681.79d2ddf61465" }
424+
it { is_expected.to be true }
425+
end
426+
427+
context "when the version has a single embedded git commit with the v suffix" do
428+
# Example: https://github.com/jenkinsci/bom/releases/tag/5622.vc9c3051619f5
429+
let(:dependency_version) { "5622.vc9c3051619f5" }
430+
let(:comparison_version) { "5681.79d2ddf61465" }
431+
it { is_expected.to be true }
432+
end
433+
434+
context "when the version contains embedded git commit with a delimiter" do
435+
# Example: https://github.com/jenkinsci/bom/releases/tag/5701.va_b_018a_a_6b_0d3
436+
let(:dependency_version) { "5701.va_b_018a_a_6b_0d3" }
437+
let(:comparison_version) { "5622.c9c3051619f5" }
438+
it { is_expected.to be true }
439+
end
440+
441+
context "when the version contains embedded git commit with a delimiter and leading character" do
442+
# Example: https://github.com/jenkinsci/bom/releases/tag/5723.v6f9c6b_d1218a_
443+
let(:dependency_version) { "5723.v6f9c6b_d1218a_" }
444+
let(:comparison_version) { "5622.c9c3051619f5" }
445+
it { is_expected.to be true }
446+
end
447+
448+
context "when only one of the version contains embedded git commits" do
449+
let(:dependency_version) { "5933.vcf06f7b_5d1a_2" }
450+
let(:comparison_version) { "5933" }
451+
it { is_expected.to be false }
452+
end
453+
454+
end
403455
end
404456
end
405457
end

0 commit comments

Comments
 (0)