PkgTemplates.jl icon indicating copy to clipboard operation
PkgTemplates.jl copied to clipboard

Badge Plugins for JuliaHub badges (Dependents, PkgEval, Version)

Open nickrobinson251 opened this issue 4 years ago • 6 comments
trafficstars

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 :)

nickrobinson251 avatar Feb 04 '21 23:02 nickrobinson251

maybe @aviks knows?

nickrobinson251 avatar Feb 04 '21 23:02 nickrobinson251

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"

for this package: deps

pfitzseb avatar Feb 05 '21 10:02 pfitzseb

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

nickrobinson251 avatar Feb 05 '21 17:02 nickrobinson251

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)

christopher-dG avatar Feb 05 '21 19:02 christopher-dG

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

ffevotte avatar Apr 04 '21 12:04 ffevotte

This package currently supports 1.0, but will stop doing so whenever something else becomes LTS

christopher-dG avatar Apr 05 '21 13:04 christopher-dG