timoschinkel / codeowners
A parser and matcher for the codeowners file as used by Github, Gitlab and Bitbucket.
Installs: 138 686
Dependents: 2
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 5
Open Issues: 0
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.4
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^5.23
README
Code Owners allows you to parse code owners files and apply the outcome to all kinds of different result sets ranging from code coverage to static analysis results.
Code Owners files are supported by Github, Gitlab and Bitbucket.
Installation
Use Composer for installation:
composer require timoschinkel/codeowners
Usage
Parse CODEOWNERS
file:
<?php use CodeOwners\Parser; use CodeOwners\PatternMatcher; try { $patterns = (new Parser())->parseFile($filename); $pattern = (new PatternMatcher(...$patterns))->match($filename); } catch (\CodeOwners\Exception\UnableToParseException $exception) { // unable to read or parse file } catch (\CodeOwners\Exception\NoMatchFoundException $exception) { // no match found }
Alternatively, parsing a string directly is also supported:
<?php use CodeOwners\Parser; use CodeOwners\PatternMatcher; try { $patterns = (new Parser())->parseString($contents); $pattern = (new PatternMatcher(...$patterns))->match($filename); } catch (\CodeOwners\Exception\UnableToParseException $exception) { // unable to read or parse file } catch (\CodeOwners\Exception\NoMatchFoundException $exception) { // no match found }
Known limitations
Currently the library does not handle spaces in file paths.