Codeowners (Codeowners v0.2.2)
View SourceA pure Elixir parser for the GitHub CODEOWNERS specification.
> Codeowners.load(".github/CODEOWNERS") |> Codeowners.rule_for_path("docs/setup.md")
%Codeowners.Rule{
pattern: "docs/*",
regex: ~r/docs/[^/]*z/,
owners: ["docs@example.com"]
}
Summary
Functions
Builds a Codeowners
struct from a string containing CODEOWNERS rules.
Loads a CODEOWNERS file from the given path, returning a Codeowners
struct.
Given a Codeowners
struct and an Elixir module, return the matching rule or empty rule.
Given a Codeowners
struct and path, return the matching rule or empty rule.
Types
@type t() :: %Codeowners{ path: String.t() | nil, root: String.t(), rules: [Codeowners.Rule.t()] }
Functions
Builds a Codeowners
struct from a string containing CODEOWNERS rules.
Parses each line generating a list of Codeowners.Rule
.
For most use cases it makes sense to use load/2
, which in turn calls build/2
Loads a CODEOWNERS file from the given path, returning a Codeowners
struct.
load/2
calls build/2
to process the contained ownership rules.
@spec rule_for_module(t(), module()) :: Codeowners.Rule.t()
Given a Codeowners
struct and an Elixir module, return the matching rule or empty rule.
rule_for_module/2
calls rule_for_path/2
.
@spec rule_for_path(t(), String.t()) :: Codeowners.Rule.t()
Given a Codeowners
struct and path, return the matching rule or empty rule.
Searches in reverse to return the last match. Handles full paths by removing the root directory before matching.