timoschinkel/codeowners

用于GitHub、Gitlab和Bitbucket的代码所有者文件的解析器和匹配器。

2.2.2 2024-07-11 13:51 UTC

This package is auto-updated.

Last update: 2024-09-11 14:11:03 UTC


README

Code Owners 允许您解析 代码所有者文件,并将结果应用于各种不同的结果集,从代码覆盖率到静态分析结果。

代码所有者文件由GitHub、GitlabBitbucket 支持。

安装

使用 Composer 进行安装

composer require timoschinkel/codeowners

用法

解析 CODEOWNERS 文件

<?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
}

或者,也可以直接解析字符串

<?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
}

已知限制

目前库不支持文件路径中的空格。