Skip to content

Commit

Permalink
Bugfixing + Better checking for version resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
VarLad committed Mar 14, 2024
1 parent 2405658 commit 9d08e74
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions src/versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,13 @@ end

const VerConfig = Tuple{Symbol, Vector{VersionNumber}, Bool}

function get_versions(name::String, pkgconf::VerConfig, head::Bool = true, regname::Union{Nothing, Vector{String}} = nothing)
versions = get_pkg_versions(name, regname)
s = pkgconf[1]
f = if s == :patches
arrange_patches
elseif s == :breaking
arrange_breaking
elseif s == :major
arrange_major
else
error("Unknown option provided $(pkgconf[1])")
end
return map(x -> f(x, versions, pkgconf[3]), pkgconf[2])
end


"""
Outputs the last patch or first patch of a version.
If the input is 1.2.3, then the output is 1.2.0 or 1.2.9 (assuming both exist, and both are the first and last patch of the version)
"""
function arrange_patches(a::VersionNumber, v::Vector{VersionNumber}, maxo::Bool)
a = filter(x -> a.minor == x.minor && a.major == x.major, v)
isempty(a) && error("No matching version found")
return maxo ? maximum(a) : minimum(a)
end

Expand All @@ -58,17 +43,35 @@ Outputs the last breaking or next breaking version.
If the input is 1.2.3, then the output is 1.2.0 or 1.3.0 (assuming both exist)
"""
function arrange_breaking(a::VersionNumber, v::Vector{VersionNumber}, maxo::Bool)
a = filter(x -> a.major == x.major && a.minor == x.minor, v)
b = filter(x -> a.major == x.major && a.minor < x.minor, v)
return maxo ? minimum(b) : minimum(a)
p = !maxo && filter(x -> a.major == x.major && a.minor == x.minor, v)
q = maxo && filter(x -> a.major == x.major && a.minor < x.minor, v)
(isempty(p) || isempty(q)) && error("No matching version found.")
return maxo ? minimum(q) : minimum(p)
end

# I believe breaking and minor are the same?i
"""
Outputs the earlier or next major version.
"""
function arrange_major(a::VersionNumber, v::Vector{VersionNumber}, maxo::Bool)
a = filter(x -> a.major < x.major, v)
b = filter(x -> a.major > x.major, v)
return maxo ? minimum(a) : maximum(b)
p = maxo && filter(x -> a.major < x.major, v)
q = !maxo && filter(x -> a.major > x.major, v)
(isempty(p) || isempty(q)) && error("No matching version found.")
return maxo ? minimum(p) : maximum(q)
end

function get_versions(name::String, pkgconf::VerConfig, head::Bool = true, regname::Union{Nothing, Vector{String}} = nothing)
versions = get_pkg_versions(name, regname)
s = pkgconf[1]
f = if s == :patches
arrange_patches
elseif s == :breaking
arrange_breaking
elseif s == :major
arrange_major
else
error("Unknown option provided $(pkgconf[1])")
end
return map(x -> f(x, versions, pkgconf[3]), pkgconf[2])
end


0 comments on commit 9d08e74

Please sign in to comment.