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.
|
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?".
|
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 trait function to return `true` for your type.
|
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
|
```@docs
|
||||||
|
needs_username
|
||||||
is_ci
|
is_ci
|
||||||
is_coverage
|
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)
|
return tags === nothing ? render(text, view) : render(text, view; tags=tags)
|
||||||
end
|
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", "project_file.jl"))
|
||||||
include(joinpath("plugins", "src_dir.jl"))
|
include(joinpath("plugins", "src_dir.jl"))
|
||||||
include(joinpath("plugins", "tests.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(::Plugin) = false
|
||||||
is_ci(::Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}) = true
|
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",
|
"URL" => "https://$(t.host)/$(t.user)/$pkg.jl",
|
||||||
"YEAR" => year(today()),
|
"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(::Plugin) = false
|
||||||
is_coverage(::Union{Codecov, Coveralls}) = true
|
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{TravisCI}) = github_pages_url
|
||||||
make_canonical(::Type{GitLabCI}) = gitlab_pages_url
|
make_canonical(::Type{GitLabCI}) = gitlab_pages_url
|
||||||
make_canonical(::Type{Nothing}) = nothing
|
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)
|
LibGit2.commit(repo, msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
needs_username(::Git) = true
|
||||||
|
@ -19,7 +19,7 @@ A configuration used to generate packages.
|
|||||||
### User Options
|
### User Options
|
||||||
- `user::AbstractString="$(default_user())"`: GitHub (or other code hosting service) username.
|
- `user::AbstractString="$(default_user())"`: GitHub (or other code hosting service) username.
|
||||||
The default value comes from the global Git config (`github.user`).
|
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.
|
- `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`).
|
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.
|
# Non-interactive constructor.
|
||||||
function Template(::Val{false}; kwargs...)
|
function Template(::Val{false}; kwargs...)
|
||||||
user = getkw(kwargs, :user)
|
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)))
|
dir = abspath(expanduser(getkw(kwargs, :dir)))
|
||||||
host = replace(getkw(kwargs, :host), r".*://" => "")
|
host = replace(getkw(kwargs, :host), r".*://" => "")
|
||||||
julia_version = getkw(kwargs, :julia_version)
|
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.
|
# User-supplied plugins come first, so that deduping the list will remove the defaults.
|
||||||
plugins = Plugin[]
|
plugins = Plugin[]
|
||||||
append!(plugins, getkw(kwargs, :plugins))
|
append!(plugins, getkw(kwargs, :plugins))
|
||||||
@ -77,6 +75,16 @@ function Template(::Val{false}; kwargs...)
|
|||||||
append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins()))
|
append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins()))
|
||||||
plugins = sort(unique(typeof, plugins); by=string)
|
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)
|
return Template(authors, dir, host, julia_version, plugins, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
@testset "Template" begin
|
@testset "Template" begin
|
||||||
@testset "Template constructor" begin
|
@testset "Template constructor" begin
|
||||||
@testset "user" begin
|
@testset "user" begin
|
||||||
if isempty(PT.default_user())
|
mock(PT.default_user => () -> "") do _du
|
||||||
@test_throws ArgumentError Template()
|
@test_throws ArgumentError Template()
|
||||||
haskey(ENV, "CI") && run(`git config --global github.user $USER`)
|
@test isempty(Template(; disable_defaults=[Git]).user)
|
||||||
end
|
end
|
||||||
|
mock(PT.default_user => () -> "username") do _du
|
||||||
@test Template().user == PT.default_user()
|
@test Template().user == PT.default_user()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@testset "authors" begin
|
@testset "authors" begin
|
||||||
@test tpl(; authors=["a"]).authors == ["a"]
|
@test tpl(; authors=["a"]).authors == ["a"]
|
||||||
|
Loading…
Reference in New Issue
Block a user