tfarla/changelog-parser

从变更日志中提取发布信息

0.1.0 2018-05-19 21:44 UTC

README

Packagist Travis Coveralls github license

需求

原因

变更日志包含关于项目所有变更的信息。这个解析器可以用来提取特定版本的信息。这些信息可以进一步分发给您的朋友、客户、同事和其他相关方。

安装

composer require tfarla/changelog-parser

用法

假设我们有以下 markdown 文件

## 1.0.0 - 2018-12-20
### Added
- A cool new feature

### Changed
- that thing that was too complex
- slow code into fast code

### Removed
- A gastly bug

当我们使用 MarkdownParser 解析该 markdown 文件时

<?php

use \TFarla\ChangelogParser\MarkdownParser;

$parser = new MarkdownParser();

$result = $parser->parse(file_get_contents('CHANGELOG.md'));

foreach ($result->getReleases() as $release) {
    echo $release->getVersion() . PHP_EOL;
    echo $release->getDate()->format('Y-m-d') . PHP_EOL;
    foreach ($release->getChanges() as $type => $changes) {
        echo $type . PHP_EOL;
        foreach ($changes as $change) {
            echo "- $change" . PHP_EOL;
        }
    }
}

那么我们将得到以下输出

1.0.0
2018-12-20
Added
- A cool new feature
Changed
- that thing that was too complex
- slow code into fast code
Removed
- A gastly bug

已测试的变更日志格式可以在 tests/fixtures 目录下找到。

运行测试

本项目使用 金文件 来断言预期行为。这些金文件应部分存储在 git 仓库中,可以通过设置环境变量 GOLDEN1 来生成

GOLDEN=1 composer test

贡献

感谢您阅读这份 README 到此,并考虑为此项目做出贡献。如果您有任何问题或建议,请随时创建问题。

如果您想修改代码,请按照以下步骤操作

  1. 将其分叉 (https://github.com/TFarla/changelog-parser)
  2. 创建您的功能分支 (git checkout -b feature/fooBar)
  3. 提交您的更改 (git commit -am '添加一些 fooBar')
  4. 将更改推送到分支 (git push origin feature/fooBar)
  5. 创建新的 Pull Request