Allow empty username when it's not used
This commit is contained in:
parent
e05e5bec0a
commit
cd40cb4b7e
@ -297,12 +297,13 @@ For more examples, see the plugins in the [Continuous Integration (CI)](@ref) an
|
||||
|
||||
For an overview of writing template files for Mustache.jl, see [Custom Template Files](@ref) in the user guide.
|
||||
|
||||
### Traits
|
||||
### Predicates
|
||||
|
||||
There are a few traits for plugin types that are occassionally used to answer questions like "does this `Template` have any code coverage plugins?".
|
||||
If you're implementing a plugin that fits into one of the following categories, it would be wise to implement the corresponding trait function to return `true` for your type.
|
||||
There are a few predicate functions for plugins that are occasionally used to answer questions like "does this `Template` have any code coverage plugins?".
|
||||
If you're implementing a plugin that fits into one of the following categories, it would be wise to implement the corresponding predicate function to return `true` for instances of your type.
|
||||
|
||||
```@docs
|
||||
needs_username
|
||||
is_ci
|
||||
is_coverage
|
||||
```
|
||||
|
@ -218,6 +218,14 @@ function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=no
|
||||
return tags === nothing ? render(text, view) : render(text, view; tags=tags)
|
||||
end
|
||||
|
||||
"""
|
||||
needs_username(::Plugin) -> Bool
|
||||
|
||||
Determine whether or not a plugin needs a Git hosting service username to function correctly.
|
||||
If you are implementing a plugin that uses the `user` field of a [`Template`](@ref), you should implement this function and return `true`.
|
||||
"""
|
||||
needs_username(::Plugin) = false
|
||||
|
||||
include(joinpath("plugins", "project_file.jl"))
|
||||
include(joinpath("plugins", "src_dir.jl"))
|
||||
include(joinpath("plugins", "tests.jl"))
|
||||
|
@ -261,3 +261,5 @@ If you are adding a CI plugin, you should implement this function and return `tr
|
||||
"""
|
||||
is_ci(::Plugin) = false
|
||||
is_ci(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}) = true
|
||||
|
||||
needs_username(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}) = true
|
||||
|
@ -24,3 +24,5 @@ view(::Citation, t::Template, pkg::AbstractString) = Dict(
|
||||
"URL" => "https://$(t.host)/$(t.user)/$pkg.jl",
|
||||
"YEAR" => year(today()),
|
||||
)
|
||||
|
||||
needs_username(::Citation) = true
|
||||
|
@ -52,3 +52,5 @@ If you are adding a coverage plugin, you should implement this function and retu
|
||||
"""
|
||||
is_coverage(::Plugin) = false
|
||||
is_coverage(::Union{Codecov, Coveralls}) = true
|
||||
|
||||
needs_username(::Union{Codecov, Coveralls}) = true
|
||||
|
@ -110,3 +110,5 @@ gitlab_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).gitlab.i
|
||||
make_canonical(::Type{TravisCI}) = github_pages_url
|
||||
make_canonical(::Type{GitLabCI}) = gitlab_pages_url
|
||||
make_canonical(::Type{Nothing}) = nothing
|
||||
|
||||
needs_username(::Documenter) = true
|
||||
|
@ -88,3 +88,5 @@ function commit(p::Git, repo::GitRepo, pkg_dir::AbstractString, msg::AbstractStr
|
||||
LibGit2.commit(repo, msg)
|
||||
end
|
||||
end
|
||||
|
||||
needs_username(::Git) = true
|
||||
|
@ -19,7 +19,7 @@ A configuration used to generate packages.
|
||||
### User Options
|
||||
- `user::AbstractString="$(default_user())"`: GitHub (or other code hosting service) username.
|
||||
The default value comes from the global Git config (`github.user`).
|
||||
If no value is obtained, an `ArgumentError` is thrown.
|
||||
If no value is obtained, many plugins that use this value will not work.
|
||||
- `authors::Union{AbstractString, Vector{<:AbstractString}}="$(default_authors())"`: Package authors.
|
||||
Like `user`, it takes its default value from the global Git config (`user.name` and `user.email`).
|
||||
|
||||
@ -61,15 +61,13 @@ Template(; interactive::Bool=false, kwargs...) = Template(Val(interactive); kwar
|
||||
# Non-interactive constructor.
|
||||
function Template(::Val{false}; kwargs...)
|
||||
user = getkw(kwargs, :user)
|
||||
isempty(user) && throw(ArgumentError("No user set, please pass user=username"))
|
||||
|
||||
authors = getkw(kwargs, :authors)
|
||||
authors isa Vector || (authors = map(strip, split(authors, ",")))
|
||||
|
||||
dir = abspath(expanduser(getkw(kwargs, :dir)))
|
||||
host = replace(getkw(kwargs, :host), r".*://" => "")
|
||||
julia_version = getkw(kwargs, :julia_version)
|
||||
|
||||
authors = getkw(kwargs, :authors)
|
||||
authors isa Vector || (authors = map(strip, split(authors, ",")))
|
||||
|
||||
# User-supplied plugins come first, so that deduping the list will remove the defaults.
|
||||
plugins = Plugin[]
|
||||
append!(plugins, getkw(kwargs, :plugins))
|
||||
@ -77,6 +75,16 @@ function Template(::Val{false}; kwargs...)
|
||||
append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins()))
|
||||
plugins = sort(unique(typeof, plugins); by=string)
|
||||
|
||||
if isempty(user)
|
||||
foreach(plugins) do p
|
||||
if needs_username(p)
|
||||
T = nameof(typeof(p))
|
||||
s = "$T: Git hosting service username is required, supply user=username"
|
||||
throw(ArgumentError(s))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Template(authors, dir, host, julia_version, plugins, user)
|
||||
end
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
@testset "Template" begin
|
||||
@testset "Template constructor" begin
|
||||
@testset "user" begin
|
||||
if isempty(PT.default_user())
|
||||
mock(PT.default_user => () -> "") do _du
|
||||
@test_throws ArgumentError Template()
|
||||
haskey(ENV, "CI") && run(`git config --global github.user $USER`)
|
||||
@test isempty(Template(; disable_defaults=[Git]).user)
|
||||
end
|
||||
mock(PT.default_user => () -> "username") do _du
|
||||
@test Template().user == PT.default_user()
|
||||
end
|
||||
@test Template().user == PT.default_user()
|
||||
end
|
||||
|
||||
@testset "authors" begin
|
||||
|
Loading…
Reference in New Issue
Block a user