paysera/lib-changelog-parser

解析由keepachangelog.com格式化的changelog.md,并转换成PHP结构并回写

1.1.2 2018-08-06 07:03 UTC

This package is auto-updated.

Last update: 2024-09-10 20:41:27 UTC


README

lib-changelog-parser 构建状态

解析并回写按照https://keepachangelog.com/en/1.0.0/规范编写的CHANGELOG.md文件,以进行程序性操作。

解析

假设您有一个变更日志

# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 1.0.1
### Added
- `php-generator:symfony-bundle` added to `phar`

## 1.0.0
### Added
- support of something.
- another feature added.
### Removed
- In particular class some method was removed.
### Changed
- Changed how things are parsed in parser.

您现在可以解析它

$parser = new ChangelogParser(new ValueExtractor(new ChangelogConfiguration()));

$changelog = $parser->parse(file_get_contents($pathToChangelog));
print_r($changelog);

解析结果的内部结构

Changelog Object
    [header:Changelog:private] => # Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
    [versions] => Array
        [0] => VersionInfo Object
            [version] => 1.0.1
            [date] => 
            [changeEntries] => Array
                [0] => ChangeEntry Object
                    [changeType] => Added
                    [changeDetails] => Array
                        [0] => ChangeDetails Object
                            [description] => `php-generator:symfony-bundle` added to `phar`
        [1] => VersionInfo Object
            [version] => 1.0.0
            [date] => 
            [changeEntries] => Array
                [0] => ChangeEntry Object
                    [changeType] => Added
                    [changeDetails] => Array
                        [0] => ChangeDetails Object
                            [description] => support of something.
                        [1] => ChangeDetails Object
                            [description] => another feature added.
                [1] => ChangeEntry Object
                    [changeType] => Removed
                    [changeDetails] => Array
                        [0] => ChangeDetails Object
                            [description] => In particular class some method was removed.
                [2] => ChangeEntry Object
                    [changeType] => Changed
                    [changeDetails] => Array
                        [0] => ChangeDetails Object
                            [description] => Changed how things are parsed in parser.

回写

您可以使用ChangelogDumpertwig模板将Changelog对象回写为markdown格式

$dumper = new ChangelogDumper(
            new ChangelogConfiguration(),
            new Twig_Environment(
                new Twig_Loader_Array([
                    'changelog.md' => file_get_contents(__DIR__ . '/../src/Template/changelog.md.twig'),
                ])
            ),
            'changelog.md'
        );

$contents = $dumper->dump($changelog);
print_r($contents)

您应该得到根据ChangelogConfiguration格式化的markdown内容

# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 1.0.1
### Added
- `php-generator:symfony-bundle` added to `phar`

## 1.0.0
### Added
- support of something.
- another feature added.
### Removed
- In particular class some method was removed.
### Changed
- Changed how things are parsed in parser.