Skip to content

Commit 92b8496

Browse files
Merge pull request #20 from tensor4all/terasaki/update-register
terasaki/update register
2 parents 6b1b192 + 8ecc3ab commit 92b8496

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/PkgBump/PkgBump.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ function bump(mode::Symbol; commit::Bool = true, push::Bool = true)::Nothing
5858
@info "Push to origin..."
5959
run(`git -C $(project_dir) push --set-upstream origin $branch`)
6060
@info "Hint: you can create a new pull request to GitHub repository via GitHub CLI:"
61-
basebranch =
62-
read(`git -C $(project_dir) rev-parse --abbrev-ref origin/HEAD`, String) |>
63-
chomp |> basename
61+
basebranch = readchomp(`git -C . rev-parse --abbrev-ref HEAD`) # e.g., main or master
6462
@info "gh pr create --base $(basebranch) --head $(branch) --title \"Bump version to $(new_version)\" --body \"This PR updates version to $(new_version)\""
6563
@info "Hint: you can merge the pull request via GitHub CLI:"
6664
@info "gh pr merge $(branch) --merge --auto --delete-branch"

src/T4ARegistrator.jl

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using LibGit2
44
using TOML: TOML
55

66
using LocalRegistry: LocalRegistry, find_package_path
7+
using LocalRegistry.RegistryTools: RegistryTools
78

89
export bumppatch, bumpminor, bumpmajor
910
include("PkgBump/PkgBump.jl")
@@ -29,37 +30,59 @@ function register(package::Union{Module,Nothing} = nothing)
2930
""")
3031

3132
d = Dict()
33+
local pkg
3234
for project_file in Base.project_names
3335
p = joinpath(package_dir, project_file)
36+
pkg = RegistryTools.Project(p)
3437
if isfile(p)
3538
d = TOML.parsefile(p)
39+
break
3640
end
3741
end
3842

3943
name = get(d, "name", nothing)
4044
version = get(d, "version", nothing)
41-
if isnothing(name)
45+
if isnothing(pkg.name)
4246
error("$(package) does not have a Project.toml or JuliaProject.toml file")
4347
end
44-
if isnothing(version)
48+
if isnothing(pkg.version)
4549
error("$(package) is not a valid package (no version)")
4650
end
4751
v = VersionNumber(version)
4852
branch = "register-$(name)-$(v)"
53+
registry = "[email protected]:tensor4all/T4ARegistry.git"
54+
4955
LocalRegistry.register(
5056
package_dir;
51-
registry = "[email protected]:tensor4all/T4ARegistry.git",
57+
registry = registry,
5258
branch = branch,
5359
commit = true,
5460
push = true,
5561
)
5662

63+
registry_path = LocalRegistry.find_registry_path(registry, pkg)
64+
gitconfig = Dict()
65+
registry_path, _ = LocalRegistry.check_git_registry(registry_path, gitconfig)
66+
new_package = !LocalRegistry.has_package(registry_path, pkg)
67+
if new_package
68+
package_repo = LocalRegistry.get_remote_repo(package_dir, gitconfig)
69+
else
70+
package_repo = ""
71+
end
72+
5773
@info "Hint: you can create a new pull request to GitHub repository via GitHub CLI:"
58-
basebranch =
59-
read(`git -C $(package_dir) rev-parse --abbrev-ref origin/HEAD`, String) |> chomp |> basename
60-
@info "gh pr create --repo tensor4all/T4ARegistry --base $(basebranch) --head $(branch)"
74+
basebranch = readchomp(`git -C . rev-parse --abbrev-ref HEAD`) # e.g., main or master
75+
76+
pr_title = "$(LocalRegistry.commit_title(pkg, new_package))"
77+
78+
tree_hash, _, _ = LocalRegistry.get_tree_hash(package_dir, gitconfig)
79+
80+
pr_body = "UUID: $(pkg.uuid)\nRepo: $(package_repo)\nTree: $(string(tree_hash))"
81+
command = "gh pr create --repo tensor4all/T4ARegistry --base $(basebranch) --head $(branch) --title \"$(pr_title)\" --body \"$(pr_body)\""
82+
println(command)
6183
@info "Hint: you can merge the pull request via GitHub CLI:"
62-
@info "gh pr merge --repo tensor4all/T4ARegistry $(branch) --merge --auto --delete-branch"
84+
println("gh pr merge --repo tensor4all/T4ARegistry $(branch) --merge --auto --delete-branch")
85+
return true
6386
end
6487

6588
end

0 commit comments

Comments
 (0)