Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Massive Refactoring and an official v0.2.0 release, if you'll take it. #3

Merged
merged 19 commits into from
Sep 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build
composer.lock
vendor
.idea/
*.bak
430 changes: 39 additions & 391 deletions CHANGELOG.md

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributor Code of Conduct

As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
* Other unethical or unprofessional conduct.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.

This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community in a direct capacity. Personal views, beliefs and values of individuals do not necessarily reflect those of the organisation or affiliated individuals and organisations.

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing
Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/ins0/github-changelog-generator).

## Pull Requests
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **Create feature branches** - Don't ask us to pull from your master branch.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

## Running Tests
```cli
$ composer test
```

**Happy coding**!
22 changes: 0 additions & 22 deletions LICENSE

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MIT License (MIT)

Copyright (c) 2015 Marco Rieger <rieger@racecore.de>

> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
120 changes: 82 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,95 @@
# github-changelog-generator
inspired by [https://github.com/skywinder/github-changelog-generator](https://github.com/skywinder/github-changelog-generator) implemented in PHP.
# GitHub ChangelogGenerator
> Creates a markdown changelog for your repository, based on your repository's releases, issues
> and pull-requests. Inspired by [github-changelog-generator][ruby-generator-link] for Ruby.

creates a markdown change log based on release tag versions and github issues.
## Installation
### Composer
```cli
$ composer require ins0/github-changelog-generator
```

## usage
## Usage
**Note:** *You can see an example of the output generated, [here](CHANGELOG.md).*

### cli
``github-changelog-generator.php.bat -u [github_user] -r [repository_name] -t [github_api_token]``
### PHP
```php
<?php
require_once 'vendor/autoload.php';

the token option is optional - without the github api calls are limited and your change log in large projects is may not fully generated
$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);

### php
$generator = new GithubChangelogGenerator('*** github_api_token ***');
$generator->createChangelog($user, $repository);

if your repository use different labels for ``features`` or ``bugs`` you need to customize the issue mapping like
// The ChangelogGenerator::generate() method does throw
// exceptions, so remember to wrap your code in try/catch blocks.
try {
$handle = fopen('CHANGELOG.md', 'w');

$issueLabelMapping = [
GithubChangelogGenerator::LABEL_TYPE_BUG => [
'otherLabelForBugs',
'moreLabels',
],
GithubChangelogGenerator::LABEL_TYPE_FEATURE => [
'otherLabelForFeatures',
'moreLabels',
],
];
$generator = new GithubChangelogGenerator('*** github_api_token ***', $issueLabelMapping);
$generator->createChangelog($user, $repository, $saveFilePath);

## example output
if (!$handle) {
throw new RuntimeException('Cannot open file for writing');
}

view ``CHANGELOG.md`` for a full change log created from [https://github.com/zendframework/modules.zendframework.com](https://github.com/zendframework/modules.zendframework.com)
// Write markdown output to file
fwrite($handle, $changelog->generate());
fclose($handle);
} catch (Exception $e) {
// handle exceptions...
}
```

# Change Log
If your repository uses labels other than `feature`, `bug` or `enhancement` you can customize them, like so:
```php
require_once 'vendor/autoload.php';

## [1.4.1](https://github.com/zendframework/modules.zendframework.com/releases/tag/1.4.1) (2015-03-09T11:24:57Z)
$labelMappings = [
GithubChangelogGenerator::LABEL_TYPE_ADDED => ['feature', 'anotherFeatureLabel'],
GithubChangelogGenerator::LABEL_TYPE_CHANGED => ['enhancement', 'anotherEnhancementLabel'],
GithubChangelogGenerator::LABEL_TYPE_FIXED => ['bug', 'anotherBugLabel']
];

**New features:**
$changelog = new ins0\GitHub\ChangelogGenerator($repository, $labelMappings);
```

- Feature: added google analytics code [\#480](https://github.com/zendframework/modules.zendframework.com/pull/480)
- Enhancement: Assert ModuleController::viewAction() is not dispatched to [\#477](https://github.com/zendframework/modules.zendframework.com/pull/477)
- Enhancement: added hhvm as allow failure [\#475](https://github.com/zendframework/modules.zendframework.com/pull/475)
- Fix: Reset before pulling in changes [\#473](https://github.com/zendframework/modules.zendframework.com/pull/473)
- [WIP] Feature: Flash Messenger Error Messages [\#421](https://github.com/zendframework/modules.zendframework.com/pull/421)
### CLI
```cli
$ php vendor/bin/github-changelog-generator ins0/github-changelog-generator > CHANGELOG.md
```

**Fixed bugs:**
## CLI
This command line tool supports output redirection/pipelining, unless the `--file` option is provided.

- Fix: Do not collect code coverage . . . for now [\#476](https://github.com/zendframework/modules.zendframework.com/pull/476)
- Fix: Do not json_decode API response to associative array [\#474](https://github.com/zendframework/modules.zendframework.com/pull/474)
**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](https://github.com/sebastianbergmann/phpunit) test suite.
```cli
$ composer test
```

## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

## Security
If you discover any security related issues, please email rieger@racecore.de instead of using the issue tracker.

## Credits
- [Marco Rieger](https://github.com/ins0)
- [Nathan Bishop](https://github.com/nbish11)

## License
The MIT License (MIT). Please see the [LICENSE](LICENSE.md) file for more information.

[ruby-generator-link]: https://github.com/skywinder/github-changelog-generator
46 changes: 46 additions & 0 deletions bin/github-changelog-generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env php
<?php

require_once '../vendor/autoload.php';

// define CLI arguments
$cli = new Commando\Command();
Copy link
Owner

@ins0 ins0 Apr 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking what would be the downside to just getting the args instead of using this dependencie?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was pretty hesitant at first at adding another library, but this has support for built in error handling/exit codes, support for arguments without a name, aliases, even a help menu; and eventually, I can easily add support for templates and label mappings (--template and --labels). These were all features I was going to add to the original, but I currently don't have the time to implement all this at the moment. This library was a shortcut until I can get around to writing an implementation that doesn't require a third party library (in other words, this dependency will be removed in a later version).

$cli->beepOnError(false);

// repository
$cli->argument(0)
->referToAs('repository')
->require()
->describedAs('The GitHub repository to generate the changelog for.')
->must(function ($val) {
// cannot begin or end with a slash, and slash can only occur once
return substr_count($val, '/') === 1 && substr($val, 0, 1) !== '/'
&& substr($val, strlen($val) - 1, 1) !== '/';
});

// GitHub token
$cli->flag('t')
->alias('token')
->describedAs('Your GitHub Account\'s OAUTH token.');

// file
$cli->flag('f')
->alias('file')
->describedAs('Write the changelog to a file');

$repository = new ins0\GitHub\Repository($cli[0], $cli['token']);
$changelog = new ins0\GitHub\ChangelogGenerator($repository);

try {
// output to CLI or write to file
if ($file = $cli['file']) {
$handle = fopen($file, 'w');
fwrite($handle, $changelog->generate());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why skipping the file save within the class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment.

Most of my changes don't make sense at the moment, but will make integrating future features much, much easier to implement.

fclose($handle);
} else {
echo $changelog->generate();
}
} catch (Exception $e) {
echo "\n", $e->getMessage(), "\n";
exit(0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed no?

Copy link
Contributor Author

@nbish11 nbish11 Apr 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try/catch block is mainly there to catch this exception and let the user know, through the CLI, that there were no repository's, while still allowing the build to pass (exit code 0).

As for moving the file writing logic outside of the class, I'm eventually going to add support for streams. This will have the added benefit of being much much faster and requiring much less memory, among other things.

}
51 changes: 51 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "ins0/github-changelog-generator",
"description": "Creates a markdown changelog for your GitHub repository.",
"type": "library",
"keywords": [
"github",
"changelog",
"markdown",
"generator",
"keepachangelog"
],
"require-dev": {
"phpunit/phpunit": "4.*"
},
"license": "MIT",
"authors": [
{
"name": "Marco Rieger",
"email": "rieger@racecore.de",
"homepage": "https://github.com/ins0",
"role": "Developer"
},
{
"name": "Nathan Bishop",
"email": "nbish11@hotmail.com",
"homepage": "https://github.com/nbish11",
"role": "Developer"
}
],
"require": {
"php": "~5.4|~7.0",
"nategood/commando": "^0.2.8"
},
"bin": [
"bin/github-changelog-generator"
],
"scripts": {
"test": "phpunit"
},
"autoload": {
"psr-4": {
"ins0\\GitHub\\": "src"
},
"classmap": ["github-changelog-generator.php"]
},
"autoload-dev": {
"psr-4": {
"ins0\\GitHub\\": "tests"
}
}
}
2 changes: 1 addition & 1 deletion github-changelog-generator-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
}

$generator = new GithubChangelogGenerator($token);
$generator->createChangelog($user, $repository, $saveFilePath);
$generator->createChangelog($user, $repository, $saveFilePath);
Loading