Codeowners (Codeowners v0.2.2)

View Source

A 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

t()

@type t() :: %Codeowners{
  path: String.t() | nil,
  root: String.t(),
  rules: [Codeowners.Rule.t()]
}

Functions

build(file_content \\ "", opts \\ [])

@spec build(String.t(), root: String.t(), path: String.t()) :: t()

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

load(path, opts \\ [])

@spec load(String.t(), [{:root, String.t()}]) :: t()

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

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

rule_for_module(codeowners, module)

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

rule_for_path(codeowners, path)

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