Merge pull request #76 from invenia/cdg/authors
Replace authors field in Project.toml
This commit is contained in:
commit
b865b9f422
@ -23,6 +23,14 @@ function generate(
|
|||||||
println(io, "\n[compat]\njulia = $(repr_version(t.julia_version))")
|
println(io, "\n[compat]\njulia = $(repr_version(t.julia_version))")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Replace the authors field with the template's authors.
|
||||||
|
if !isempty(t.authors)
|
||||||
|
path = joinpath(pkg_dir, "Project.toml")
|
||||||
|
project = read(path, String)
|
||||||
|
authors = string("[", join(map(repr ∘ strip, split(t.authors, ",")), ", "), "]")
|
||||||
|
write(path, replace(project, r"authors = .*" => "authors = $authors"))
|
||||||
|
end
|
||||||
|
|
||||||
if git
|
if git
|
||||||
# Initialize the repo.
|
# Initialize the repo.
|
||||||
repo = LibGit2.init(pkg_dir)
|
repo = LibGit2.init(pkg_dir)
|
||||||
|
@ -74,7 +74,9 @@ struct Template
|
|||||||
# If no author was set, look for one in the global git config.
|
# If no author was set, look for one in the global git config.
|
||||||
if isempty(authors)
|
if isempty(authors)
|
||||||
authors = LibGit2.getconfig("user.name", "")
|
authors = LibGit2.getconfig("user.name", "")
|
||||||
elseif isa(authors, Vector)
|
email = LibGit2.getconfig("user.email", "")
|
||||||
|
isempty(email) || (authors *= " <$email>")
|
||||||
|
elseif authors isa Vector
|
||||||
authors = join(authors, ", ")
|
authors = join(authors, ", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -39,10 +39,10 @@ write(test_file, template_text)
|
|||||||
|
|
||||||
@testset "Template creation" begin
|
@testset "Template creation" begin
|
||||||
# Checking default field assignments.
|
# Checking default field assignments.
|
||||||
t = Template(; user=me)
|
t = Template(; authors="foo", user=me)
|
||||||
@test t.user == me
|
@test t.user == me
|
||||||
@test t.license == "MIT"
|
@test t.license == "MIT"
|
||||||
@test t.authors == LibGit2.getconfig("user.name", "")
|
@test t.authors == "foo"
|
||||||
@test t.dir == default_dir
|
@test t.dir == default_dir
|
||||||
@test t.julia_version == PkgTemplates.default_version()
|
@test t.julia_version == PkgTemplates.default_version()
|
||||||
@test !t.ssh
|
@test !t.ssh
|
||||||
@ -109,14 +109,14 @@ end
|
|||||||
pkg_dir = replace(default_dir, homedir() => "~")
|
pkg_dir = replace(default_dir, homedir() => "~")
|
||||||
ver = PkgTemplates.version_floor(PkgTemplates.default_version())
|
ver = PkgTemplates.version_floor(PkgTemplates.default_version())
|
||||||
buf = IOBuffer()
|
buf = IOBuffer()
|
||||||
t = Template(; user=me)
|
t = Template(; user=me, authors="foo")
|
||||||
show(buf, t)
|
show(buf, t)
|
||||||
text = String(take!(buf))
|
text = String(take!(buf))
|
||||||
expected = """
|
expected = """
|
||||||
Template:
|
Template:
|
||||||
→ User: $me
|
→ User: $me
|
||||||
→ Host: github.com
|
→ Host: github.com
|
||||||
→ License: MIT ($(LibGit2.getconfig("user.name", "")) $(year(today())))
|
→ License: MIT (foo $(year(today())))
|
||||||
→ Package directory: $pkg_dir
|
→ Package directory: $pkg_dir
|
||||||
→ Minimum Julia version: v$ver
|
→ Minimum Julia version: v$ver
|
||||||
→ SSH remote: No
|
→ SSH remote: No
|
||||||
|
Loading…
Reference in New Issue
Block a user