PkgTemplates.jl
PkgTemplates.jl copied to clipboard
Badge Plugins for JuliaHub badges (Dependents, PkgEval, Version)
I noticed the Dependents badge on the Arrow.jl repo, and thought it was kinda cool.
Turns out this is through JuliaHub, and they provide Version and PkgEval badges too, see e.g. https://discourse.julialang.org/t/package-badges-on-juliahub/44635
These could easily be added as BadgePlugins if we new how the URL is generated e.g.
struct DependentsBadge <: BadgePlugin end
function badges(::DependentsBadge)
return Badge(
"Dependent Packages",
"https://juliahub.com/docs/{{{PKG}}}/deps.svg",
"https://juliahub.com/ui/Packages/{{{PKG}}}/QnF3w", # <- need to know what these 5 "random" chars will be
)
end
I suppose we'd also need a view method, like view(::DependentsBadge, ::Template, pkg::AbstractString) = Dict("PKG" => pkg, "RANDOM_CHARS" => "QnF3w")
So i don't know if this would be possible, but maybe someone who works on JuliaHub knows :)
maybe @aviks knows?
You can get the package slug with Base.package_slug(pkg_uuid, 5), so e.g.
julia> Base.package_slug(UUID("14b8a8f1-9102-5b29-a752-f990bacb7fe1"), 5)
"IGiQL"
thanks! hmm, okay. I guess we could get the UUID from the Project.toml of the newly created repo (if the new repo is the active env), with something like
uuid_line = readlines(Base.active_project())[2];
uuid = only(match(r"\"(.*?)\"", uuid_line).captures);
slug = Base.package_slug(UUID(uuid), 5)
maybe/hopefully someone can come up with something nicer
I would recommend using Pkg's TOML parser to get the UUID, instead of assuming where the UUID will be (alternatively and more simply, a regex would do the trick)
Assuming that the environment of the newly created package is active, why not rely on Pkg to find its UUID?
using Pkg
Base.package_slug(Pkg.project().uuid, 5)
It does require a fairly recent version of Julia though (>=1.5 IIRC), which might be considered too restrictive
This package currently supports 1.0, but will stop doing so whenever something else becomes LTS