CodeOwnersEntry Class

Represents a single line of a CODEOWNERS file, associating a file pattern with its owners.

// Parse a CODEOWNERS file
var file = CodeOwnersFile.Parse("*.js @user1 @user2", CodeOwnersDialect.GitLab);
var entry = file.Entries[0];
Assert.Equal("*.js", entry.Pattern);
Assert.Equal(["@user1", "@user2"], entry.Owners.Select(owner => owner.ToString()));
public sealed class CodeOwnersEntry : IEquatable<CodeOwnersEntry>

Remarks

Entries are returned in the order they appear in the file. CODEOWNERS resolution is last-match-wins, so the last entry whose CodeOwnersEntry.Pattern matches a path owns it.

Implements

Properties

NameDescription
IsExclusionGets a value indicating whether the entry is a GitLab exclusion: its pattern starts with an unescaped !.
IsOptionalGets a value indicating whether this entry belongs to an optional section.
OwnersGets the owners of the pattern. Empty when the entry explicitly leaves the pattern unowned.
PatternGets the file pattern (e.g., "*.js", "/docs/*", or "*") that this entry applies to, without its escape characters.
SectionGets the section this entry belongs to, or null if not part of a section.

Gets a value indicating whether the entry is a GitLab exclusion: its pattern starts with an unescaped !.

public bool IsExclusion { get; }

Property value

bool

Remarks

A path that matches an exclusion of a section has no owners in this section, whatever the order of the entries. The CodeOwnersEntry.Pattern of an exclusion keeps its leading !. The GitHub dialect has no exclusions: a ! is an ordinary character.

Gets a value indicating whether this entry belongs to an optional section.

public bool IsOptional { get; }

Property value

bool

Gets the owners of the pattern. Empty when the entry explicitly leaves the pattern unowned.

public IReadOnlyList<CodeOwner> Owners { get; }

Gets the file pattern (e.g., "*.js", "/docs/*", or "*") that this entry applies to, without its escape characters.

public string Pattern { get; }

Property value

string

Gets the section this entry belongs to, or null if not part of a section.

public CodeOwnersSection? Section { get; }

Property value

CodeOwnersSection?

Methods

NameDescription
Equals(CodeOwnersEntry?)
Equals(object?)
GetHashCode()
IsMatch(string)Determines whether the pattern of the entry matches the path of a file, as the host of the dialect does.
ToString()Returns the entry as written in a CODEOWNERS file: the pattern, with its escape characters, followed by the owners.

Equals overloads

Equals(CodeOwnersEntry?)

CodeOwnersEntry.cs
public bool Equals(CodeOwnersEntry? other)
Parameters
other CodeOwnersEntry?
Returns

bool

No documentation is available.

Equals(object?)

CodeOwnersEntry.cs
public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetHashCode()

CodeOwnersEntry.cs
public override int GetHashCode()

Returns

int

No documentation is available.

IsMatch(string)

CodeOwnersEntry.cs

Determines whether the pattern of the entry matches the path of a file, as the host of the dialect does.

public bool IsMatch(string path)

Parameters

path string
The path of a file, relative to the root of the repository, with / as the separator. A leading / is ignored. The comparison is case-sensitive.

Returns

bool true when the pattern matches path; otherwise, false. For an exclusion, the pattern is read without its leading !.

Remarks

This method ignores the other entries of the file. Use CodeOwnersFile.FindEntries to find the entries that own a path, which applies the last-match-wins rule, the sections and the exclusions.

Returns the entry as written in a CODEOWNERS file: the pattern, with its escape characters, followed by the owners.

public override string ToString()

Returns

string

Remarks

The section header is not part of the entry: parse the line after CodeOwnersSection.ToString to read the entry back.

Operators

NameDescription
operator ==(CodeOwnersEntry?, CodeOwnersEntry?)
operator !=(CodeOwnersEntry?, CodeOwnersEntry?)

operator ==(CodeOwnersEntry?, CodeOwnersEntry?)

CodeOwnersEntry.cs
public static bool operator ==(CodeOwnersEntry? left, CodeOwnersEntry? right)

Parameters

left CodeOwnersEntry?
right CodeOwnersEntry?

Returns

bool

No documentation is available.

operator !=(CodeOwnersEntry?, CodeOwnersEntry?)

CodeOwnersEntry.cs
public static bool operator !=(CodeOwnersEntry? left, CodeOwnersEntry? right)

Parameters

left CodeOwnersEntry?
right CodeOwnersEntry?

Returns

bool

No documentation is available.