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
0 commit comments