Skip to content

Commit aba4640

Browse files
authored
Merge pull request #384 from oxinabox/ox/codeowners
Add CodeOwners Plugin
2 parents cb0e6a9 + 63a9b5c commit aba4640

File tree

7 files changed

+47
-2
lines changed

7 files changed

+47
-2
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PkgTemplates"
22
uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1"
33
authors = ["Chris de Graaf", "Invenia Technical Computing Corporation"]
4-
version = "0.7.30"
4+
version = "0.7.31"
55

66
[deps]
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/PkgTemplates.jl

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export
2222
CirrusCI,
2323
Citation,
2424
Codecov,
25+
CodeOwners,
2526
ColPracBadge,
2627
CompatHelper,
2728
Coveralls,

src/plugin.jl

+1
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ include(joinpath("plugins", "git.jl"))
355355
include(joinpath("plugins", "tagbot.jl"))
356356
include(joinpath("plugins", "develop.jl"))
357357
include(joinpath("plugins", "coverage.jl"))
358+
include(joinpath("plugins", "codeowners.jl"))
358359
include(joinpath("plugins", "ci.jl"))
359360
include(joinpath("plugins", "compat_helper.jl"))
360361
include(joinpath("plugins", "citation.jl"))

src/plugins/codeowners.jl

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
CodeOwners <: Plugin
3+
CodeOwners(; owners)
4+
5+
A plugin which created GitLab/GitHub compatible CODEOWNERS files.
6+
owners should be a vector of patterns mapped to a vector of owner names.
7+
For example:
8+
`owners=["*"=>["@invenia"], "README.md"=>["@documentation","@oxinabox]]`
9+
assigns general ownership over all files to the invenia group,
10+
but assigns ownership of the readme to the documentation group and to the user oxinabox.
11+
12+
By default, it creates an empty CODEOWNERS file.
13+
"""
14+
@plugin struct CodeOwners <: Plugin
15+
owners::Vector{Pair{String,Vector{String}}} = Vector{Pair{String,Vector{String}}}()
16+
end
17+
18+
PkgTemplates.destination(::CodeOwners) = "CODEOWNERS"
19+
20+
function render_plugin(p::CodeOwners)
21+
join((pattern * " " * join(subowners, " ") for (pattern, subowners) in p.owners), "\n")
22+
end
23+
24+
function PkgTemplates.hook(p::CodeOwners, t::Template, pkg_dir::AbstractString)
25+
pkg = basename(pkg_dir)
26+
path = joinpath(pkg_dir, destination(p))
27+
text = render_plugin(p)
28+
PkgTemplates.gen_file(path, text)
29+
end
30+
31+
function PkgTemplates.validate(p::CodeOwners, ::Template)
32+
for (pattern, subowners) in p.owners
33+
contains(pattern, r"\s") && throw(ArgumentError(("Pattern ($pattern) must not contain whitespace")))
34+
for subowner in subowners
35+
contains(subowner, r"\s") && throw(ArgumentError("Owner name ($subowner) must not contain whitespace"))
36+
'@' subowner || throw(ArgumentError("Owner name ($subowner) must be `@user` or `[email protected]`"))
37+
end
38+
end
39+
end

test/fixtures/AllPlugins/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

test/fixtures/WackyOptions/CODEOWNERS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* @user
2+
README.md @group [email protected]

test/reference.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ end
8888

8989
@testset "All plugins" begin
9090
test_all("AllPlugins"; authors=USER, plugins=[
91-
AppVeyor(), CirrusCI(), Citation(), Codecov(), CompatHelper(), Coveralls(),
91+
AppVeyor(), CirrusCI(), Citation(), Codecov(), CompatHelper(), Coveralls(), CodeOwners(),
9292
Develop(), Documenter(), DroneCI(), GitHubActions(), GitLabCI(), TravisCI(), RegisterAction(),
9393
])
9494
end
@@ -117,6 +117,7 @@ end
117117
CirrusCI(; image="freebsd-123", coverage=false, extra_versions=["1.3"]),
118118
Citation(; readme=true),
119119
Codecov(; file=STATIC_TXT),
120+
CodeOwners(; owners=["*"=>["@user"], "README.md"=>["@group","[email protected]"]]),
120121
CompatHelper(; cron="0 0 */3 * *"),
121122
Coveralls(; file=STATIC_TXT),
122123
Documenter{GitHubActions}(;

0 commit comments

Comments
 (0)