vdhicts / keepachangelog-parser
Keep A Changelog 标准的解析器
v2.2.0
2024-03-17 06:30 UTC
Requires
- php: >=8.1
- illuminate/support: ^9.0|^10.0|^11.0
- laravel/pint: ^1.7
- league/commonmark: ^2.2
- symfony/css-selector: ^6.0|^7.0
- symfony/dom-crawler: ^6.0|^7.0
Requires (Dev)
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^10.0
README
Keep A Changelog 标准的解析器。
需求
此包至少需要 PHP 8.1 或更高版本。
安装
您可以通过 composer 安装此包
composer require vdhicts/keepachangelog-parser
用法
此包旨在易于使用。
解析更改日志
$content = file_get_contents('CHANGELOG.md'); $parser = new \Vdhicts\KeepAChangelog\Parser(); $changelog = $parser->parse($content);
使用不同的日期格式
默认情况下,解析器将以 Y-m-d
格式解析发行版。如果您想使用其他格式,只需将格式传递给 setDateFormat
函数即可。
$content = file_get_contents('CHANGELOG.md'); $parser = new \Vdhicts\KeepAChangelog\Parser(); $changelog = $parser ->setDateFormat('Y-m-d H:i:s') ->parse($content);
访问更改日志
解析器将返回一个包含 Release
模型的 Changelog
模型,其中包含一组 Section
模型。
更改日志有几种方法可以检索信息
// Get the description of the changelog, which returns an array of lines $descriptionHtml = implode('<br>', $changelog->getDescription()); // Determine if the changelog has any releases $changelog->hasReleases(); // Get the unreleased section $unreleased = $changelog->getUnreleased(); // Get the latest release $latestRelease = $changelog->getLatestRelease();
当检索所有发行版时,最新的将是第一个,如果有未发布的,则未发布的将是最后一个。
发行版有几个方法可以获取有关发行版的信息
// Determine if the current one is the unreleased section $isUnreleased = $release->isUnreleased(); // Get the version for the release $version = $release->getVersion(); // Get the release date, will be null when not released or a date isn't provided $data = $release->getReleasedAt(); // Get the tag reference, usually something like https://github.com/vdhicts/keepachangelog-parser/compare/v0.0.1...v1.0.0 $tagReference = $release->getTagReference(); // Get a specific section of the release $added = $release->getSection(Section::ADDED); // Get the collection of sections for the release $sections = $release->getSections();
部分由类型(如添加等)和条目数组组成
$type = $section->getType(); $entries = $section->getEntries(); $entriesHtml = implode('<br>', $entries);
测试
单元测试位于 tests
文件夹中。运行
composer test
当您想要一个代码覆盖率报告,它将在 build/report
文件夹中生成时。运行
composer test-coverage
贡献
欢迎任何贡献,但它应该符合 PSR-12 标准,并且请为每个功能/错误创建一个 pull request。作为交换,您将在这个页面上被列为贡献者。
安全性
如果您在此或其他 Vdhicts 包中发现任何安全问题,请通过电子邮件security@vdhicts.nl 而不是使用问题跟踪器。
支持
如果您在此解析器中遇到问题或有关于它的疑问,请随时在 GitHub 上打开一个问题。
许可证
此包是开源软件,根据 MIT 许可证 许可。
关于 Vdhicts
Vdhicts 是我的个人公司名称,我在那里作为自由职业者工作。Vdhicts 为企业和教育机构开发和实施 IT 解决方案。