PkgTemplates.jl/src/plugins/codecov.jl

67 lines
2.1 KiB
Julia
Raw Normal View History

2017-08-11 22:18:09 +00:00
"""
CodeCov(; config_file::AbstractString="") -> CodeCov
2017-08-11 22:18:09 +00:00
Add CodeCov to a template's plugins to enable CodeCov coverage reports.
# Keyword Arguments:
* `config_file::AbstractString`: Path to a custom `.codecov.yml`.
If `nothing` is supplied, then no file will be generated.
2017-08-11 22:18:09 +00:00
"""
2017-08-14 18:12:37 +00:00
@auto_hash_equals struct CodeCov <: Plugin
2017-08-11 22:18:09 +00:00
gitignore_files::Vector{AbstractString}
2017-08-14 18:59:33 +00:00
config_file::Union{AbstractString, Void}
2017-08-11 22:18:09 +00:00
2017-08-14 18:59:33 +00:00
function CodeCov(; config_file::Union{AbstractString, Void}="")
if config_file != nothing
if isempty(config_file)
config_file = joinpath(DEFAULTS_DIR, "codecov.yml")
end
if !isfile(abspath(config_file))
throw(ArgumentError("File $config_file does not exist"))
end
2017-08-11 22:18:09 +00:00
end
new(["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], config_file)
end
end
"""
2017-08-14 18:59:33 +00:00
badges(\_::CodeCov, pkg_name::AbstractString, t::Template) -> Vector{String}
2017-08-11 22:18:09 +00:00
Generate Markdown badges for the current package.
2017-08-11 22:18:09 +00:00
# Arguments
2017-08-14 18:59:33 +00:00
* `_::CodeCov`: plugin whose badges we are generating.
2017-08-11 22:18:09 +00:00
* `t::Template`: Template configuration options.
* `pkg_name::AbstractString`: Name of the package.
Returns an array of Markdown badges.
2017-08-11 22:18:09 +00:00
"""
2017-08-14 18:59:33 +00:00
function badges(_::CodeCov, t::Template, pkg_name::AbstractString)
2017-08-11 22:18:09 +00:00
user = strip(URI(t.remote_prefix).path, '/')
return [
2017-08-15 14:19:37 +00:00
"[![CodeCov](https://codecov.io/gh/$user/$pkg_name.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/$user/$pkg_name.jl)"
2017-08-11 22:18:09 +00:00
]
end
"""
gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString) -> Vector{String}
2017-08-11 22:18:09 +00:00
Generate a .codecov.yml.
# Arguments
* `plugin::CodeCov`: Plugin whose files are being generated.
* `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package.
Returns an array of generated files.
2017-08-11 22:18:09 +00:00
"""
function gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString)
if plugin.config_file == nothing
return String[]
end
2017-08-11 22:18:09 +00:00
text = substitute(readstring(plugin.config_file), pkg_name, template)
pkg_dir = joinpath(template.path, pkg_name)
gen_file(joinpath(pkg_dir, ".codecov.yml"), text)
return [".codecov.yml"]
end