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

Correctly handle an edge case in the sequential version check #563

Merged
merged 6 commits into from
Jun 13, 2024
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RegistryCI"
uuid = "0c95cc5f-2f7e-43fe-82dd-79dbcba86b32"
authors = ["Dilum Aluthge <[email protected]>", "Fredrik Ekre <[email protected]>", "contributors"]
version = "10.3.0"
version = "10.3.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
10 changes: 10 additions & 0 deletions src/AutoMerge/guidelines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,16 @@ end

function _valid_change(old_version::VersionNumber, new_version::VersionNumber)
diff = difference(old_version, new_version)
if !(diff isa VersionNumber)
if diff isa ErrorCannotComputeVersionDifference
old_msg = diff.msg
else
T = typeof(diff)
old_msg = "Unknown diff type: $(T)"
end
new_msg = "Error occured while trying to compute version bump. Message: $(old_msg)"
return _invalid_sequential_version(new_msg)
end
@debug("Difference between versions: ", old_version, new_version, diff)
if diff == v"0.0.1"
return true, "", :patch
Expand Down
6 changes: 3 additions & 3 deletions src/AutoMerge/semver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ function difference(x::VersionNumber, y::VersionNumber)
elseif y.patch > x.patch
return VersionNumber(y.major - x.major, y.minor - x.minor, y.patch - x.patch)
else
throw(
ArgumentError("first argument must be strictly less than the second argument")
)
msg = "first argument $(x) must be strictly less than the second argument $(y)"
@warn msg x y
return ErrorCannotComputeVersionDifference(msg)
end
end

Expand Down
4 changes: 4 additions & 0 deletions src/AutoMerge/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ struct AutoMergeWrongBuildType <: AutoMergeException
msg::String
end

struct ErrorCannotComputeVersionDifference
msg::String
end

struct GitHubAutoMergeData
# Handle to the GitHub API. Used to query the PR and update
# comments and status.
Expand Down
4 changes: 2 additions & 2 deletions test/automerge-unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ end
@test AutoMerge.nextmajor(v"1.2") == v"2"
@test AutoMerge.nextmajor(v"1.2.3") == v"2"
@test AutoMerge.difference(v"1", v"2") == v"1"
@test_throws ArgumentError AutoMerge.difference(v"1", v"1")
@test_throws ArgumentError AutoMerge.difference(v"2", v"1")
@test AutoMerge.difference(v"1", v"1") isa AutoMerge.ErrorCannotComputeVersionDifference
@test AutoMerge.difference(v"2", v"1") isa AutoMerge.ErrorCannotComputeVersionDifference
@test !AutoMerge._has_upper_bound(Pkg.Types.VersionRange("0"))
@test AutoMerge._has_upper_bound(Pkg.Types.VersionRange("1"))
@test !AutoMerge._has_upper_bound(Pkg.Types.VersionRange("*"))
Expand Down
Loading