Skip to content

Commit

Permalink
add support for commit hash information
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Dec 31, 2023
1 parent 10a0449 commit 74d78fa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
38 changes: 32 additions & 6 deletions src/AutoMerge/guidelines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -619,17 +619,22 @@ const guideline_src_names_OK = Guideline(;
)

function meets_code_can_be_downloaded(registry_head, pkg, version, pr; pkg_code_path)
uuid, package_repo, subdir, tree_hash_from_toml = parse_registry_pkg_info(
uuid, package_repo, subdir, tree_hash_from_toml, commit_hash_from_toml, tag_hash_from_toml, tag_name_from_toml = parse_registry_pkg_info(
registry_head, pkg, version
)

# We get the `tree_hash` two ways and check they agree, which helps ensures the `subdir` parameter is correct. Two ways:
# 1. By the commit hash in the PR body and the subdir parameter
# 1. By the commit hash and the subdir parameter
# 2. By the tree hash in the Versions.toml

commit_hash = commit_from_pull_request_body(pr)
if isnothing(commit_hash_from_toml)
# git-commit-sha1 is an optional registry key: if it isn't in the .toml, then we query the PR
commit_hash = commit_from_pull_request_body(pr)
else
commit_hash = commit_hash_from_toml
end

local tree_hash_from_commit, tree_hash_from_commit_success
local tree_hash_from_commit, tree_hash_from_commit_success, tag_success
clone_success = load_files_from_url_and_tree_hash(
pkg_code_path, package_repo, tree_hash_from_toml
) do dir
Expand All @@ -639,6 +644,23 @@ function meets_code_can_be_downloaded(registry_head, pkg, version, pr; pkg_code_
@error e
"", false
end

tag_success = try
if !isnothing(tag_hash_from_toml)
commit_hash_from_tag = readchomp(Cmd(`git rev-parse $(tag_hash_from_toml)^\{commit\}`; dir=dir))
@assert commit_hash_from_tag == commit_hash_from_toml
end
if !isnothing(tag_name_from_toml)
hash_from_tag_name = readchomp(Cmd(`git rev-parse $(tag_name_from_toml)`; dir=dir))
# if an annotated tag, should point to the tag object
# if a lightweight tag, should point to the commit object
@assert hash_from_tag_name == something(tag_hash_from_toml, commit_hash_from_toml)
end
true
catch e
@error e
false
end
end

if !clone_success
Expand All @@ -654,9 +676,13 @@ function meets_code_can_be_downloaded(registry_head, pkg, version, pr; pkg_code_
@error "`tree_hash_from_commit != tree_hash_from_toml`" tree_hash_from_commit tree_hash_from_toml
return false,
"Tree hash obtained from the commit message and subdirectory does not match the tree hash in the Versions.toml file. Possibly this indicates that an incorrect `subdir` parameter was passed during registration."
else
return true, ""
end

if !tag_success
return false, "Tag information in .toml does not match information in repository"
end

return true
end

function _generate_pkg_add_command(pkg::String, version::VersionNumber)::String
Expand Down
12 changes: 10 additions & 2 deletions src/AutoMerge/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@ function parse_registry_pkg_info(registry_path, pkg, version=nothing)
subdir = convert(String, get(package, "subdir", ""))
if version === nothing
tree_hash = nothing
commit_hash = nothing
tag_hash = nothing
tag_name = nothing
else
versions = TOML.parsefile(
joinpath(registry_path, packages[uuid]["path"], "Versions.toml")
)
tree_hash = convert(String, versions[string(version)]["git-tree-sha1"])
version_info = versions[string(version)]
tree_hash = convert(String, version_info["git-tree-sha1"])
commit_hash = get(version_info, "git-commit-sha1", nothing)
tag_hash = get(version_info, "git-tag-sha1", nothing)
tag_name = get(version_info, "git-tag-name", nothing)
subdir = get(version_info, "subdir", subdir) # use version-specific subdir if it exists
end
return (; uuid=uuid, repo=repo, subdir=subdir, tree_hash=tree_hash)
return (; uuid=uuid, repo=repo, subdir=subdir, tree_hash=tree_has, commit_hash=commit_hash, tag_hash=tag_hash, tag_name=tag_name)
end

function _comment_disclaimer(; point_to_slack::Bool=false)
Expand Down
2 changes: 1 addition & 1 deletion src/registry_testing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function test(path=pwd(); registry_deps::Vector{<:AbstractString}=String[])
# https://github.com/JuliaRegistries/RegistryCI.jl/issues/523
# "yanked" is correct.
# "yank" (and all other variants) are incorrect.
Test.@test keys(data) ["git-tree-sha1", "yanked"]
Test.@test keys(data) ["git-tree-sha1", "git-commit-sha1", "git-tag-sha1", "git-tag-name", "subdir", "yanked"]
end

# Deps.toml testing
Expand Down

0 comments on commit 74d78fa

Please sign in to comment.