View Source Codeowners (Codeowners v0.1.4)

A pure Elixir parser for the Github CODEOWNERS specification.

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

Link to this function

build(file_content \\ "")

View Source
@spec build(String.t()) :: t()

Builds a Codeowners struct from a string containing CODEOWNERS rules.

Parses each line generating a list of Codeowners.Rule. Stores File.cwd/0 as :root.

For most use cases it makes sense to use load/1, which in turn calls build/1

@spec load(String.t()) :: t()

Loads a CODEOWNERS file from the given path, returning a Codeowners struct.

load/1 calls build/1 to process the contained ownership rules.

Link to this function

rule_for_module(codeowners, module)

View Source
@spec rule_for_module(t(), module()) :: Codeowners.Rule.t()

Given a Codeowners struct and an Elixir module, return the matching rule or empty rule.

Codeowners.rule_for_module calls Codeowners.rule_for_path.

Link to this function

rule_for_path(codeowners, path)

View Source
@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.