Creates a markdown changelog for your repository, based on your repository's releases, issues and pull-requests. Inspired by github-changelog-generator for Ruby.
$ composer require ins0/github-changelog-generator
Note: You can see an example of the output generated, here.
<?php
require_once 'vendor/autoload.php';
$token = '...'; // The token is not required, but is still recommended.
$repository = new ins0\GitHub\Repository('ins0/github-changelog-generator', $token);
$changelog = new ins0\GitHub\ChangelogGenerator($repository);
// The ChangelogGenerator::generate() method does throw
// exceptions, so remember to wrap your code in try/catch blocks.
try {
$handle = fopen('CHANGELOG.md', 'w');
if (!$handle) {
throw new RuntimeException('Cannot open file for writing');
}
// Write markdown output to file
fwrite($handle, $changelog->generate());
fclose($handle);
} catch (Exception $e) {
// handle exceptions...
}
If your repository uses labels other than feature
, bug
or enhancement
you can customize them, like so:
require_once 'vendor/autoload.php';
$labelMappings = [
ins0\GitHub\ChangelogGenerator::LABEL_TYPE_ADDED => ['feature', 'anotherFeatureLabel'],
ins0\GitHub\ChangelogGenerator::LABEL_TYPE_CHANGED => ['enhancement', 'anotherEnhancementLabel'],
ins0\GitHub\ChangelogGenerator::LABEL_TYPE_FIXED => ['bug', 'anotherBugLabel']
];
$changelog = new ins0\GitHub\ChangelogGenerator($repository, $labelMappings);
If you would like to customize the section headers, you can override the built in ones or add additional
require_once 'vendor/autoload.php';
$typeHeadings = [
ins0\GitHub\ChangelogGenerator::LABEL_TYPE_ADDED => '### New stuff!'
];
$changelog = new ins0\GitHub\ChangelogGenerator($repository, [], $labelHeaders);
$ php vendor/bin/github-changelog-generator ins0/github-changelog-generator > CHANGELOG.md
This command line tool supports output redirection/pipelining, unless the --file
option is provided.
Required:
[repository]
: The url to your GitHub repository, without the domain. E.g.ins0/github-changelog-generator
Boolean:
- This tool does not use any boolean flags.
Optional:
--token
(-t
): Your GithHub OAUTH token.--file
(-f
): Write output to a file.--help
: Access the help menu.
Exit Codes:
0
: success1
: fail
This library uses the PHPUnit test suite.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see the LICENSE file for more information.