bramdevries/changelog

适用于普通开发者的 http://keepachangelog.com/ 解析器

0.12.0 2021-02-05 12:42 UTC

README

像专业人士一样解析变更日志

此包使得解析 keepachangelog.com 格式的变更日志变得简单

安装

composer require bramdevries/changelog

使用方法

解析整个变更日志

以下变更日志

# Change Log
A change log for the change log parser

## 0.2.0 - 2014-11-22

### Added

* `getChanges` method to retrieve a single release

## 0.1.0 - 2014-11-22

### Added

* `getReleases` method that retrieves the releases described in a change log
* `toJson` method that creates a json representation of a change log.
$parser = new Changelog\Parser(file_get_contents('CHANGELOG.md');
echo $parser->toJson();

将返回

{
  "description": "A change log for the change log parser",
  "releases": [
    {
      "name": "0.0.1",
      "date": "2014-11-22",
      "changes": {
        "added": [
          "<code>getReleases</code> method that retrieves the releases described in a change log",
          "<code>toJson</code> method that creates a json representation of a change log."
        ]
      }
    }
  ]
}

解析单个版本号的变更日志

例如:如果你想以这种格式解析一个拉取请求

  ### Added
  - Addition 1
  - Addition 2

  ### Changed
  - Change 1
  - Change 2

  ### Removed
  - Removal 1
  - Removal 2
// Assuming $content contains the above markdown
$parser = new Changelog\Parser($content);
echo $parser->getChanges();

返回

{
  "added": [
    "Addition 1",
    "Addition 2"
  ],
  "changed": [
    "Change 1",
    "Change 2"
  ],
  "removed": [
    "Removal 1",
    "Removal 2"
  ]
}