Skip to content

Generate change logs from your repositorys on GitHub. Based on releases, issues, labels and pull requests

License

Notifications You must be signed in to change notification settings

ins0/github-changelog-generator

Repository files navigation

GitHub ChangelogGenerator

Creates a markdown changelog for your repository, based on your repository's releases, issues and pull-requests. Inspired by github-changelog-generator for Ruby.

Installation

Composer

$ composer require ins0/github-changelog-generator

Usage

Note: You can see an example of the output generated, here.

PHP

<?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);

CLI

$ php vendor/bin/github-changelog-generator ins0/github-changelog-generator > CHANGELOG.md

CLI

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: success
  • 1: fail

Testing

This library uses the PHPUnit test suite.

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see the LICENSE file for more information.

About

Generate change logs from your repositorys on GitHub. Based on releases, issues, labels and pull requests

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages