CodeOwnersFile Class

Represents a parsed CODEOWNERS file.

var file = CodeOwnersFile.Parse("* @user1\n*.js @js-owner", CodeOwnersDialect.GitHub);

Assert.Equal("*", file.Entries[0].Pattern);
Assert.Equal("@user1", file.Entries[0].Owners[0].ToString());

Assert.Equal("*.js", file.Entries[1].Pattern);
Assert.Equal("@js-owner", file.Entries[1].Owners[0].ToString());
public sealed class CodeOwnersFile

Remarks

An instance only exists for a valid file: CodeOwnersFile.Parse throws and CodeOwnersFile.TryParse returns false rather than returning a partially parsed file.

Properties

NameDescription
EntriesGets the entries of the file, in the order they appear in it.

Gets the entries of the file, in the order they appear in it.

public IReadOnlyList<CodeOwnersEntry> Entries { get; }

Property value

IReadOnlyList<CodeOwnersEntry>

Remarks

CODEOWNERS resolution is last-match-wins, so the last entry whose CodeOwnersEntry.Pattern matches a path owns it.

Methods

NameDescription
Parse(ReadOnlySpan<char>, CodeOwnersDialect)Parses the content of a CODEOWNERS file.
Parse(string, CodeOwnersDialect)Parses the content of a CODEOWNERS file.
TryParse(ReadOnlySpan<char>, CodeOwnersDialect, CodeOwnersFile?)Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid.
TryParse(ReadOnlySpan<char>, CodeOwnersDialect, CodeOwnersFile?, CodeOwnersParseError)Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid.
TryParse(string, CodeOwnersDialect, CodeOwnersFile?)Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid.
TryParse(string, CodeOwnersDialect, CodeOwnersFile?, CodeOwnersParseError)Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid.

Parse overloads

Parse(ReadOnlySpan<char>, CodeOwnersDialect)

CodeOwnersFile.cs

Parses the content of a CODEOWNERS file.

public static CodeOwnersFile Parse(ReadOnlySpan<char> content, CodeOwnersDialect dialect)
Parameters
content ReadOnlySpan<char>
The content of the CODEOWNERS file.
dialect CodeOwnersDialect
The syntax content uses. Sections are only recognized by CodeOwnersDialect.GitLab.
Returns

CodeOwnersFile The parsed CodeOwnersFile.

Exceptions
CodeOwnersParseException
content is not a valid CODEOWNERS file. Parsing stops at the first error.
Remarks

The returned CodeOwnersFile does not reference content: every value it exposes is copied out of it.

Parse(string, CodeOwnersDialect)

CodeOwnersFile.cs

Parses the content of a CODEOWNERS file.

public static CodeOwnersFile Parse(string content, CodeOwnersDialect dialect)
Parameters
content string
The content of the CODEOWNERS file.
dialect CodeOwnersDialect
The syntax content uses. Sections are only recognized by CodeOwnersDialect.GitLab.
Returns

CodeOwnersFile The parsed CodeOwnersFile.

Exceptions
CodeOwnersParseException
content is not a valid CODEOWNERS file. Parsing stops at the first error.

TryParse overloads

TryParse(ReadOnlySpan<char>, CodeOwnersDialect, CodeOwnersFile?)

CodeOwnersFile.cs

Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid.

public static bool TryParse(ReadOnlySpan<char> content, CodeOwnersDialect dialect, out CodeOwnersFile? file)
Parameters
content ReadOnlySpan<char>
The content of the CODEOWNERS file.
dialect CodeOwnersDialect
The syntax content uses. Sections are only recognized by CodeOwnersDialect.GitLab.
file CodeOwnersFile?
When this method returns true, contains the parsed CodeOwnersFile; otherwise, null.
Returns

bool true when content is a valid CODEOWNERS file; otherwise, false.

Remarks

Use the CodeOwnersFile.TryParse overload to know why the file is invalid.

TryParse(ReadOnlySpan<char>, CodeOwnersDialect, CodeOwnersFile?, CodeOwnersParseError)

CodeOwnersFile.cs

Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid.

public static bool TryParse(ReadOnlySpan<char> content, CodeOwnersDialect dialect, out CodeOwnersFile? file, out CodeOwnersParseError error)
Parameters
content ReadOnlySpan<char>
The content of the CODEOWNERS file.
dialect CodeOwnersDialect
The syntax content uses. Sections are only recognized by CodeOwnersDialect.GitLab.
file CodeOwnersFile?
When this method returns true, contains the parsed CodeOwnersFile; otherwise, null.
error CodeOwnersParseError
When this method returns false, contains the first error found in content; otherwise, default.
Returns

bool true when content is a valid CODEOWNERS file; otherwise, false.

Remarks

The parsed CodeOwnersFile does not reference content: every value it exposes is copied out of it.

TryParse(string, CodeOwnersDialect, CodeOwnersFile?)

CodeOwnersFile.cs

Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid.

public static bool TryParse(string content, CodeOwnersDialect dialect, out CodeOwnersFile? file)
Parameters
content string
The content of the CODEOWNERS file.
dialect CodeOwnersDialect
The syntax content uses. Sections are only recognized by CodeOwnersDialect.GitLab.
file CodeOwnersFile?
When this method returns true, contains the parsed CodeOwnersFile; otherwise, null.
Returns

bool true when content is a valid CODEOWNERS file; otherwise, false.

Remarks

Use the CodeOwnersFile.TryParse overload to know why the file is invalid.

TryParse(string, CodeOwnersDialect, CodeOwnersFile?, CodeOwnersParseError)

CodeOwnersFile.cs

Parses the content of a CODEOWNERS file and returns a value indicating whether it is valid.

public static bool TryParse(string content, CodeOwnersDialect dialect, out CodeOwnersFile? file, out CodeOwnersParseError error)
Parameters
content string
The content of the CODEOWNERS file.
dialect CodeOwnersDialect
The syntax content uses. Sections are only recognized by CodeOwnersDialect.GitLab.
file CodeOwnersFile?
When this method returns true, contains the parsed CodeOwnersFile; otherwise, null.
error CodeOwnersParseError
When this method returns false, contains the first error found in content; otherwise, default.
Returns

bool true when content is a valid CODEOWNERS file; otherwise, false.