Compare commits

..

35 Commits

Author SHA1 Message Date
Petr Korolev
64acef9554 add travis comand 2017-11-30 18:20:45 +03:00
Marco Ferrari
e87b267b0e Implemented a Dockerfile (#592)
* Implemented a Dockerfile. See skywinder/github-changelog-generator#591

* Set Ferrari Marco as a maintainer

* Explicitly install the latest released version
2017-11-23 14:08:50 +01:00
Olle Jonsson
72452a1315 CHANGELOG for v1.15.0-rc 2017-10-29 19:03:26 +01:00
Olle Jonsson
9377fe600a v1.15.0-rc 2017-10-29 18:59:21 +01:00
Olle Jonsson
11a7243de1 README: Markdown typo [ci skip] 2017-10-29 17:54:43 +01:00
Olle Jonsson
307994e11f Merge pull request #578 from olleolleolle/improve-abort-on-missing-info
Aborting on missing --user and --project prints all of usage
2017-10-27 09:48:35 +02:00
Olle Jonsson
4465adf943 Linting 2017-10-27 09:29:17 +02:00
Olle Jonsson
5834fd3766 Update parser.rb 2017-10-27 09:28:52 +02:00
Olle Jonsson
b486425af1 Parser: less wordy output 2017-10-27 09:28:52 +02:00
Olle Jonsson
91ac00c1d3 Abort with friendly message on no user or project 2017-10-27 09:28:52 +02:00
Olle Jonsson
4f640b74ac Aborting prints all of usage 2017-10-27 09:28:52 +02:00
Olle Jonsson
178ebfb1e7 Travis: in smoke tests, skip codeclimate 2017-10-27 09:00:08 +02:00
Olle Jonsson
eef787d74d Travis: use pre-installed Rubies
- for faster feedback
2017-10-27 08:52:23 +02:00
Olle Jonsson
faf2ddd552 Linting 2017-10-27 08:49:52 +02:00
Olle Jonsson
14c36317f1 Merge pull request #584 from olleolleolle/fix/rake-task-missing-options
Add Rake options reported missing
2017-10-26 14:45:02 +02:00
Olle Jonsson
deb902ae13 Add Rake options reported missing 2017-10-26 01:35:51 +02:00
Olle Jonsson
10e6287866 Merge pull request #576 from olleolleolle/fix/docs-for-api
Options#print_options + API docs for Options, Parser
2017-10-14 22:13:12 +02:00
Olle Jonsson
5bb4d51b96 Options#print_options: tell don't ask 2017-10-14 21:52:26 +02:00
Olle Jonsson
1fac4efe47 [docs] API docs for Options, Parser
- shorten implementation of print_options
2017-10-14 21:28:02 +02:00
Olle Jonsson
ad0d972ed9 Add option --require to load custom Ruby code (#574) 2017-10-14 21:00:56 +02:00
Olle Jonsson
79518161b8 [docs] Contributing file (#575)
- [ci skip]
2017-10-14 15:33:34 +02:00
Olle Jonsson
db0e848208 CHANGELOG for v1.15.0.pre.beta 2017-10-13 21:14:22 +02:00
Olle Jonsson
d16bf4cfaa v1.15.0-beta 2017-10-13 21:08:09 +02:00
Ewoud Kohl van Wijngaarden
fe7c585ed1 Fix regression w/ enhancements in issues_to_log (#573)
Introduced in 21ec2db39b.
2017-10-13 06:08:59 +02:00
Olle Jonsson
3f8fb60af3 OctoFetcher: Use defaults for request_options (#571)
* OctoFetcher: rely on default args

  - in iterate_pages

* OctoFetcher: extract options method
2017-10-10 23:48:00 +02:00
Olle Jonsson
23b341f715 OctoFetcher: extract methods (#570)
* OctoFetcher: extract methods

* OctoFetcher: extract github_options smethod

* OctoFetcher: Document exception, name parameters

  - more communicative names

* OctoFetcher#fetch_github_token: simplify

  - using ActiveSupport

* OctoFetcher#init_cache: fewer statements

* OctoFetcher: inline calls, name parameters

* OctoFetcher: name parameters, inline local
2017-10-10 23:05:10 +02:00
Olle Jonsson
630b8cee88 OctoFetcher: extract method fail_with_message (#569) 2017-10-10 21:42:29 +02:00
Olle Jonsson
74fdc2026a OctoFetcher: drop unused number_of_pages feature (#568) 2017-10-10 21:22:17 +02:00
Tim Meusel
21ec2db39b Add breaking-changes section to changelog (#530)
* add breaking-changes section to changelog

* Clean up parse_by_sections

* Thank you bastelfreak and ekohl!
2017-10-10 20:27:23 +02:00
Olle Jonsson
d1e09f6964 Travis: Do not test on jruby-head (#567) 2017-10-10 20:11:36 +02:00
Olle Jonsson
b36d85eb53 Drop Project-and-Username-finding code (#451)
* Remove Project-and-Username finding code and usages

* Remove "github_remote" option, now unused

* Update README: Usage has changed
2017-10-10 19:53:21 +02:00
Ben Holden-Crowther
1658b41dff Update license date to a range (#553)
* Update license date to a range containing 2017
2017-10-05 23:38:23 +02:00
Florian Thomas
64f4cd07c9 filter tags correctly when since_tag is set to most recent tag (#566)
* filter tags correctly when `since_tag` is set to most recent tag
Before this fix [`filtered_tags`](https://github.com/skywinder/github-changelog-generator/blob/master/lib/github_changelog_generator/generator/generator_generation.rb#L132)
was empty which caused a fallback to the last tag in the sorted_tags array (which is the oldest tag).
There for no issues and PRs were filtered in that case.

fixes #555
fixes #304
2017-10-05 23:15:06 +02:00
Olle Jonsson
7cbe41555a Drop unused Rake task (#564) 2017-10-04 09:06:49 +02:00
Olle Jonsson
dd956b7b95 CHANGELOG for v1.15.0.pre.alpha 2017-10-01 15:47:16 +02:00
26 changed files with 779 additions and 628 deletions

View File

@@ -0,0 +1,2 @@
project=github-changelog-generator
user=skywinder

View File

@@ -4,28 +4,23 @@ cache:
before_install: before_install:
- gem install bundler - gem install bundler
matrix: matrix:
fast_finish: true
include: include:
- rvm: 2.2.8 - rvm: 2.2.7
install: true # This skips 'bundle install' install: true # This skips 'bundle install'
script: gem build github_changelog_generator && gem install *.gem script: gem build github_changelog_generator && gem install *.gem
- rvm: 2.2.8 after_success: true # This skips 'codeclimate-test-reporter'
- rvm: 2.2.7
install: true # This skips 'bundle install' install: true # This skips 'bundle install'
script: gem build github_changelog_generator && bundle install script: gem build github_changelog_generator && bundle install
gemfile: spec/install-gem-in-bundler.gemfile gemfile: spec/install-gem-in-bundler.gemfile
- rvm: 2.3.5 after_success: true # This skips 'codeclimate-test-reporter'
- rvm: 2.4.2 - rvm: 2.3.4
- rvm: 2.4.1
- rvm: jruby-9.1.13.0 - rvm: jruby-9.1.13.0
jdk: oraclejdk8 jdk: oraclejdk8
env: env:
- JRUBY_OPTS=--debug - JRUBY_OPTS=--debug
- rvm: jruby-head
jdk: oraclejdk8
env:
- JRUBY_OPTS=--debug
- DEBUG=1
allow_failures:
- rvm: jruby-head
fast_finish: true
addons: addons:
code_climate: code_climate:
@@ -33,3 +28,4 @@ addons:
secure: iMpV5IAvH+/EVGZrpWnt2BnmNFzSbsRcIumsr4ZyLC8N5nrCSXyjCSy0g48btL3Sj0bSgK9hcrJsmrFd2bkqFleyAcPAzNyUQzBuIRZx47O8yFmbZ+Pj+l3+KOlmcbzJNHfDfxkxuWTmTAcSDfsiyApin721T/ey3SUuwKpZNUc= secure: iMpV5IAvH+/EVGZrpWnt2BnmNFzSbsRcIumsr4ZyLC8N5nrCSXyjCSy0g48btL3Sj0bSgK9hcrJsmrFd2bkqFleyAcPAzNyUQzBuIRZx47O8yFmbZ+Pj+l3+KOlmcbzJNHfDfxkxuWTmTAcSDfsiyApin721T/ey3SUuwKpZNUc=
after_success: after_success:
- bundle exec codeclimate-test-reporter - bundle exec codeclimate-test-reporter
- bash <(curl -s https://copilot.blackducksoftware.com/ci/travis/scripts/upload)

View File

@@ -1,5 +1,115 @@
# Change Log # Change Log
## [v1.15.0-rc](https://github.com/skywinder/github-changelog-generator/tree/v1.15.0-rc) (2017-10-29)
[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/v1.15.0.pre.beta...v1.15.0-rc)
**Implemented enhancements:**
- Add option --require to load custom Ruby code before starting [\#574](https://github.com/skywinder/github-changelog-generator/pull/574) ([olleolleolle](https://github.com/olleolleolle))
**Fixed bugs:**
- issue\_line\_labels and breaking\_labels fail as rake file config params [\#583](https://github.com/skywinder/github-changelog-generator/issues/583)
**Merged pull requests:**
- Add Rake options reported missing [\#584](https://github.com/skywinder/github-changelog-generator/pull/584) ([olleolleolle](https://github.com/olleolleolle))
- Aborting on missing --user and --project prints all of usage [\#578](https://github.com/skywinder/github-changelog-generator/pull/578) ([olleolleolle](https://github.com/olleolleolle))
- Options\#print\_options + API docs for Options, Parser [\#576](https://github.com/skywinder/github-changelog-generator/pull/576) ([olleolleolle](https://github.com/olleolleolle))
- \[docs\] Contributing file [\#575](https://github.com/skywinder/github-changelog-generator/pull/575) ([olleolleolle](https://github.com/olleolleolle))
## [v1.15.0.pre.beta](https://github.com/skywinder/github-changelog-generator/tree/v1.15.0.pre.beta) (2017-10-13)
[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/v1.15.0.pre.alpha...v1.15.0.pre.beta)
**Implemented enhancements:**
- add breaking-changes section to changelog [\#530](https://github.com/skywinder/github-changelog-generator/pull/530) ([bastelfreak](https://github.com/bastelfreak))
- Drop Project-and-Username-finding code [\#451](https://github.com/skywinder/github-changelog-generator/pull/451) ([olleolleolle](https://github.com/olleolleolle))
**Fixed bugs:**
- since\_tag doesn't work when tag specified is the latest tag [\#555](https://github.com/skywinder/github-changelog-generator/issues/555)
- since\_tag seems to not be working [\#304](https://github.com/skywinder/github-changelog-generator/issues/304)
- filter tags correctly when `since\_tag` is set to most recent tag [\#566](https://github.com/skywinder/github-changelog-generator/pull/566) ([Crunch09](https://github.com/Crunch09))
**Closed issues:**
- SSL Cert issue on Windows [\#475](https://github.com/skywinder/github-changelog-generator/issues/475)
**Merged pull requests:**
- Fix regression w/ enhancements in issues\_to\_log [\#573](https://github.com/skywinder/github-changelog-generator/pull/573) ([ekohl](https://github.com/ekohl))
- OctoFetcher: Use defaults for request\_options [\#571](https://github.com/skywinder/github-changelog-generator/pull/571) ([olleolleolle](https://github.com/olleolleolle))
- OctoFetcher: extract methods [\#570](https://github.com/skywinder/github-changelog-generator/pull/570) ([olleolleolle](https://github.com/olleolleolle))
- OctoFetcher: extract method fail\_with\_message [\#569](https://github.com/skywinder/github-changelog-generator/pull/569) ([olleolleolle](https://github.com/olleolleolle))
- OctoFetcher: drop unused number\_of\_pages feature [\#568](https://github.com/skywinder/github-changelog-generator/pull/568) ([olleolleolle](https://github.com/olleolleolle))
- Travis: Do not test on jruby-head [\#567](https://github.com/skywinder/github-changelog-generator/pull/567) ([olleolleolle](https://github.com/olleolleolle))
- Drop unused Rake task [\#564](https://github.com/skywinder/github-changelog-generator/pull/564) ([olleolleolle](https://github.com/olleolleolle))
- Update license date [\#553](https://github.com/skywinder/github-changelog-generator/pull/553) ([benhc123](https://github.com/benhc123))
## [v1.15.0.pre.alpha](https://github.com/skywinder/github-changelog-generator/tree/v1.15.0.pre.alpha) (2017-10-01)
[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/v1.14.3...v1.15.0.pre.alpha)
**Implemented enhancements:**
- Add newline after version name and Full Changelog link [\#548](https://github.com/skywinder/github-changelog-generator/pull/548) ([ianroberts131](https://github.com/ianroberts131))
- Update the token failure example to OctoKit 404 failure [\#525](https://github.com/skywinder/github-changelog-generator/pull/525) ([00xcoffee](https://github.com/00xcoffee))
- Rescue invalid commands and present the valid options list [\#498](https://github.com/skywinder/github-changelog-generator/pull/498) ([Lucashuang0802](https://github.com/Lucashuang0802))
- bundled cacert.pem with --ssl-ca-file PATH option [\#480](https://github.com/skywinder/github-changelog-generator/pull/480) ([olleolleolle](https://github.com/olleolleolle))
- Option parsing: Remove tag1, tag2 cruft [\#479](https://github.com/skywinder/github-changelog-generator/pull/479) ([olleolleolle](https://github.com/olleolleolle))
**Fixed bugs:**
- Credit line bug [\#541](https://github.com/skywinder/github-changelog-generator/issues/541)
- Bug: Credit line about this project added more than once [\#507](https://github.com/skywinder/github-changelog-generator/issues/507)
- v1.14.0 Fails with missing /tmp/ path on Windows [\#458](https://github.com/skywinder/github-changelog-generator/issues/458)
- failure when creating changelog from a repo in an orginazation: can't convert Github::ResponseWrapper to Array [\#253](https://github.com/skywinder/github-changelog-generator/issues/253)
- warn\_if\_nonmatching\_regex should display proper help message when used with exclude-tags-regex [\#551](https://github.com/skywinder/github-changelog-generator/pull/551) ([lacostej](https://github.com/lacostej))
- Bugfix: require ActiveSupport core\_ext/blank [\#520](https://github.com/skywinder/github-changelog-generator/pull/520) ([olleolleolle](https://github.com/olleolleolle))
- Create temporary cache files in Dir.tmpdir [\#459](https://github.com/skywinder/github-changelog-generator/pull/459) ([olleolleolle](https://github.com/olleolleolle))
**Closed issues:**
- error \(Windows: Command exited with code 1\) [\#536](https://github.com/skywinder/github-changelog-generator/issues/536)
- Error in generating changelog on Windows [\#521](https://github.com/skywinder/github-changelog-generator/issues/521)
- Crash on start [\#512](https://github.com/skywinder/github-changelog-generator/issues/512)
- Error On Running Generation Command [\#511](https://github.com/skywinder/github-changelog-generator/issues/511)
- Not working [\#510](https://github.com/skywinder/github-changelog-generator/issues/510)
- PR cited in the wrong TAG [\#503](https://github.com/skywinder/github-changelog-generator/issues/503)
- 404 Not Found Error [\#484](https://github.com/skywinder/github-changelog-generator/issues/484)
**Merged pull requests:**
- Travis: Configure cache: bundler: true [\#563](https://github.com/skywinder/github-changelog-generator/pull/563) ([olleolleolle](https://github.com/olleolleolle))
- Travis: use JRuby 9.1.13.0; don't redo rvm's job [\#562](https://github.com/skywinder/github-changelog-generator/pull/562) ([olleolleolle](https://github.com/olleolleolle))
- Travis: update CI matrix [\#561](https://github.com/skywinder/github-changelog-generator/pull/561) ([olleolleolle](https://github.com/olleolleolle))
- Fix section mapping, hiding untagged PRs, and hiding untagged issues [\#550](https://github.com/skywinder/github-changelog-generator/pull/550) ([hunner](https://github.com/hunner))
- Update generator\_generation.rb [\#542](https://github.com/skywinder/github-changelog-generator/pull/542) ([Lucashuang0802](https://github.com/Lucashuang0802))
- AppVeyor: drop init build hook, add .gitattributes instead [\#539](https://github.com/skywinder/github-changelog-generator/pull/539) ([olleolleolle](https://github.com/olleolleolle))
- AppVeyor: Windows configuration to pass RuboCop [\#538](https://github.com/skywinder/github-changelog-generator/pull/538) ([olleolleolle](https://github.com/olleolleolle))
- Fix the syntax ambiguity on credit-line-bug [\#537](https://github.com/skywinder/github-changelog-generator/pull/537) ([Lucashuang0802](https://github.com/Lucashuang0802))
- Credit line bug [\#535](https://github.com/skywinder/github-changelog-generator/pull/535) ([Lucashuang0802](https://github.com/Lucashuang0802))
- Update README.md [\#534](https://github.com/skywinder/github-changelog-generator/pull/534) ([Lucashuang0802](https://github.com/Lucashuang0802))
- Delete circle.yml [\#532](https://github.com/skywinder/github-changelog-generator/pull/532) ([Lucashuang0802](https://github.com/Lucashuang0802))
- Update README.md [\#531](https://github.com/skywinder/github-changelog-generator/pull/531) ([Lucashuang0802](https://github.com/Lucashuang0802))
- Remove all old credit lines in the output then add a new one [\#526](https://github.com/skywinder/github-changelog-generator/pull/526) ([Enether](https://github.com/Enether))
- Travis: jruby-9.1.10.0 [\#523](https://github.com/skywinder/github-changelog-generator/pull/523) ([olleolleolle](https://github.com/olleolleolle))
- Travis CI: Drop 2.1 [\#517](https://github.com/skywinder/github-changelog-generator/pull/517) ([olleolleolle](https://github.com/olleolleolle))
- Chore: Rubocop 0.49.0 [\#516](https://github.com/skywinder/github-changelog-generator/pull/516) ([olleolleolle](https://github.com/olleolleolle))
- Travis: use jruby-9.1.9.0 [\#506](https://github.com/skywinder/github-changelog-generator/pull/506) ([olleolleolle](https://github.com/olleolleolle))
- Use closed\_at and merged\_at when filtering issues/prs [\#504](https://github.com/skywinder/github-changelog-generator/pull/504) ([unicolet](https://github.com/unicolet))
- Remove --between-tags option [\#501](https://github.com/skywinder/github-changelog-generator/pull/501) ([Lucashuang0802](https://github.com/Lucashuang0802))
- Fixed headline in README.md [\#496](https://github.com/skywinder/github-changelog-generator/pull/496) ([Dreckiger-Dan](https://github.com/Dreckiger-Dan))
- Update README.md [\#490](https://github.com/skywinder/github-changelog-generator/pull/490) ([fatData](https://github.com/fatData))
- Travis: use latest rubies [\#488](https://github.com/skywinder/github-changelog-generator/pull/488) ([olleolleolle](https://github.com/olleolleolle))
- Use ruby-2.4.1 in CI [\#487](https://github.com/skywinder/github-changelog-generator/pull/487) ([olleolleolle](https://github.com/olleolleolle))
- Travis: jruby-9.1.8.0 [\#485](https://github.com/skywinder/github-changelog-generator/pull/485) ([olleolleolle](https://github.com/olleolleolle))
- Update to latest CodeClimate [\#478](https://github.com/skywinder/github-changelog-generator/pull/478) ([olleolleolle](https://github.com/olleolleolle))
- Gemspec: update retriable to 3.0 [\#477](https://github.com/skywinder/github-changelog-generator/pull/477) ([olleolleolle](https://github.com/olleolleolle))
- Travis: new JRuby, develop on 2.4.0 [\#476](https://github.com/skywinder/github-changelog-generator/pull/476) ([olleolleolle](https://github.com/olleolleolle))
- Fix readme typos [\#467](https://github.com/skywinder/github-changelog-generator/pull/467) ([dguo](https://github.com/dguo))
- Gemspec: demand rainbow 2.2.1+ [\#466](https://github.com/skywinder/github-changelog-generator/pull/466) ([olleolleolle](https://github.com/olleolleolle))
## [v1.14.3](https://github.com/skywinder/github-changelog-generator/tree/v1.14.3) (2016-12-31) ## [v1.14.3](https://github.com/skywinder/github-changelog-generator/tree/v1.14.3) (2016-12-31)
[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/v1.14.2...v1.14.3) [Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/v1.14.2...v1.14.3)

60
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,60 @@
# How to contribute
Bug reports and pull requests from users is what keeps this project working.
## Basics
1. Create an issue and describe your idea
2. [Fork it](https://github.com/skywinder/github-changelog-generator/fork)
3. Create your feature branch (`git checkout -b my-new-feature`)
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Publish the branch (`git push origin my-new-feature`)
6. Create a new Pull Request
## Checking your work
You can test your workflow with changelog generator with
[the skywinder/changelog_test repo].
You can run the test suite.
You can run [RuboCop] to check code style.
The default Rake task, runnable using `rake`, calls `rubocop`, then `spec`.
[the skywinder/changelog_test repo]: https://github.com/skywinder/changelog_test/
[RuboCop]: http://rubocop.readthedocs.io/en/latest/
## Write documentation
This project has documentation in a few places:
### Introduction and usage
A friendly `README.md` written for many audiences.
### Examples and advanced usage
The [wiki].
### API documentation
API documentation is written as [YARD] docblocks in the Ruby code.
This is rendered as Web pages on [Rubydoc.info][github-changelog-generator on Rubydoc.info].
The completeness of the API documentation is measured on [our page on the Inch CI Web site][github-changelog-generator on Inch CI]
### man page
`man/git-generate-changelog.md`
The man page is for the `git generate-changelog` Git sub-command, which is a wrapper for `github_changelog_generator`. That file is a Markdown file.
Use the [ronn] gem to generate `.1` and `.html` artifacts like this: `cd man; ronn git-generate-changelog.md`
[wiki]: https://github.com/skywinder/github-changelog-generator/wiki
[YARD]: https://yardoc.org/
[github-changelog-generator on Rubydoc.info]: http://www.rubydoc.info/gems/github_changelog_generator
[ronn]: https://github.com/rtomayko/ronn
[github-changelog-generator on Inch CI]: https://inch-ci.org/github/skywinder/github-changelog-generator

16
Dockerfile Normal file
View File

@@ -0,0 +1,16 @@
FROM ruby:2.4-alpine3.6
LABEL maintainer "ferrari.marco@gmail.com"
ENV GITHUB_CHANGELOG_GENERATOR_VERSION "1.14.3"
RUN gem install github_changelog_generator --version $GITHUB_CHANGELOG_GENERATOR_VERSION
ENV SRC_PATH /usr/local/src/your-app
RUN mkdir -p $SRC_PATH
VOLUME [ "$SRC_PATH" ]
WORKDIR $SRC_PATH
CMD ["--help"]
ENTRYPOINT ["github_changelog_generator"]

View File

@@ -1,5 +1,5 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Petr Korolev Copyright (c) 2016-2017 Petr Korolev
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: 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:

View File

@@ -30,9 +30,14 @@ GitHub Changelog Generator ![GitHub Logo](../master/images/logo.jpg)
Since you don't have to fill your `CHANGELOG.md` manually now: just run the script, relax and take a cup of :coffee: before your next release! :tada: Since you don't have to fill your `CHANGELOG.md` manually now: just run the script, relax and take a cup of :coffee: before your next release! :tada:
### *Whats the point of a change log?* ### *Whats the point of a change log?*
To make it easier for users and contributors to see precisely what notable changes have been made between each release (or version) of the project. To make it easier for users and contributors to see precisely what notable changes have been made between each release (or version) of the project.
### *Why should I care?* ### *Why should I care?*
Because software tools are for people. If you dont care, why are you contributing to open source? Surely, there must be a kernel (ha!) of care somewhere in that lovely little brain of yours.
Because software tools are for _people_. "Changelogs make it easier for users and
contributors to see precisely what notable changes have been made between each
release (or version) of the project."
:arrow_right: *[http://keepachangelog.com](http://keepachangelog.com)* :arrow_right: *[http://keepachangelog.com](http://keepachangelog.com)*
@@ -42,6 +47,10 @@ Because software tools are for people. If you dont care, why are you contribu
See also Troubleshooting. See also Troubleshooting.
## Running with Docker
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app skywinder/github-changelog-generator
## Output example ## Output example
- Look at **[CHANGELOG.md](https://github.com/skywinder/Github-Changelog-Generator/blob/master/CHANGELOG.md)** for this project - Look at **[CHANGELOG.md](https://github.com/skywinder/Github-Changelog-Generator/blob/master/CHANGELOG.md)** for this project
@@ -71,32 +80,31 @@ See also Troubleshooting.
## Usage ## Usage
**It's really simple!**
- If your **`git remote`** `origin` refers to your GitHub repo, just go to your project folder and run: - Run this:
github_changelog_generator
- Or, run this from anywhere:
`github_changelog_generator -u github_username -p github_project` `github_changelog_generator -u github_username -p github_project`
`github_changelog_generator github_username/github_project` `github_changelog_generator github_username/github_project`
- If you are running it against a repository on a Github Enterprise install, you must specify *both* `--github-site` and `--github-api` command line options: - For Github Enterprise repos, specify *both* `--github-site` and `--github-api` options:
github_changelog_generator --github-site="https://github.yoursite.com" \ github_changelog_generator --github-site="https://github.yoursite.com" \
--github-api="https://github.yoursite.com/api/v3/" --github-api="https://github.yoursite.com/api/v3/"
This generates a changelog to the `CHANGELOG.md` file, with pretty markdown formatting. This generates a `CHANGELOG.md`, with pretty Markdown formatting.
### Params ### Params
Type `github_changelog_generator --help` for details. Type `github_changelog_generator --help` for details.
For more details about params, read the Wiki page: [**Advanced change log generation examples**](https://github.com/skywinder/github-changelog-generator/wiki/Advanced-change-log-generation-examples) For more details about params, read the Wiki page: [**Advanced change log generation examples**](https://github.com/skywinder/github-changelog-generator/wiki/Advanced-change-log-generation-examples)
### Params File ### Params File
In your project root, you can put a params file named `.github_changelog_generator` to override default params: In your project root, you can put a params file named `.github_changelog_generator` to override default params:
Example: Example:
``` ```
unreleased=false unreleased=false
future-release=5.0.0 future-release=5.0.0
@@ -106,6 +114,7 @@ since-tag=1.0.0
### GitHub token ### GitHub token
GitHub only allows 50 unauthenticated requests per hour. GitHub only allows 50 unauthenticated requests per hour.
Therefore, it's recommended to run this script with authentication by using a **token**. Therefore, it's recommended to run this script with authentication by using a **token**.
Here's how: Here's how:
@@ -143,7 +152,7 @@ If you have a `HISTORY.md` file in your project, it will automatically be picked
You love `rake`? We do, too! So, we've made it even easier for you: You love `rake`? We do, too! So, we've made it even easier for you:
we've provided a `rake` task library for your changelog generation. we've provided a `rake` task library for your changelog generation.
Just put something like this in your `Rakefile`: Configure the task in your `Rakefile`:
```ruby ```ruby
require 'github_changelog_generator/task' require 'github_changelog_generator/task'
@@ -154,11 +163,14 @@ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
end end
``` ```
All command line options can be passed to the `rake` task as `config` parameters. And since you're naming the `rake` task yourself, you can create as many as you want. All command-line options can be passed to the `rake` task as `config`
parameters. And since you're naming the `rake` task yourself, you can create
as many as you want.
You can look for params names from the [parser source code (#setup_parser)](https://github.com/skywinder/github-changelog-generator/blob/master/lib/github_changelog_generator/parser.rb). For example, to translate the bugs label to Portuguese, instead of setting `config.bugs_label`, you have to set `config.bug_prefix`, and so on. You can look for params names from the [parser source code (#setup_parser)](https://github.com/skywinder/github-changelog-generator/blob/master/lib/github_changelog_generator/parser.rb). For example, to translate the bugs label to Portuguese, instead of setting `config.bugs_label`, you have to set `config.bug_prefix`, and so on.
## Features and advantages of this project ## Features and advantages of this project
- Generate canonical, neat change log file, followed by [basic change log guidelines](http://keepachangelog.com) :gem: - Generate canonical, neat change log file, followed by [basic change log guidelines](http://keepachangelog.com) :gem:
- Optionally generate **Unreleased** changes (closed issues that have not released yet) :dizzy: - Optionally generate **Unreleased** changes (closed issues that have not released yet) :dizzy:
- **GitHub Enterprise support** via command line options! :factory: - **GitHub Enterprise support** via command line options! :factory:
@@ -179,17 +191,19 @@ You can look for params names from the [parser source code (#setup_parser)](http
### Alternatives ### Alternatives
Here is a [wikipage list of alternatives](https://github.com/skywinder/Github-Changelog-Generator/wiki/Alternatives) that I found. But none satisfied my requirements. Here is a [wikipage list of alternatives](https://github.com/skywinder/Github-Changelog-Generator/wiki/Alternatives) that I found. But none satisfied my requirements.
*If you know other projects, feel free to edit this Wiki page!* *If you know other projects, feel free to edit this Wiki page!*
### Projects using this library ### Projects using this library
Here's a [wikipage list of projects](https://github.com/skywinder/Github-Changelog-Generator/wiki/Projects-using-Github-Changelog-Generator). Here's a [wikipage list of projects](https://github.com/skywinder/Github-Changelog-Generator/wiki/Projects-using-Github-Changelog-Generator).
If you've used this project in a live app, please let me know! Nothing makes me happier than seeing someone else take my work and go wild with it. If you've used this project in a live app, please let me know! Nothing makes me happier than seeing someone else take my work and go wild with it.
*If you are using `github_changelog_generator` to generate your project's changelog, or know of other projects using it, please [add it to this list] (https://github.com/skywinder/Github-Changelog-Generator/wiki/Projects-using-Github-Changelog-Generator).* *If you are using `github_changelog_generator` to generate your project's changelog, or know of other projects using it, please [add it to this list](https://github.com/skywinder/github-changelog-generator/wiki/Projects-using-Github-Changelog-Generator).*
## Am I missing some essential feature? ## Am I missing some essential feature?
@@ -260,15 +274,9 @@ can't get the latest version of Ruby installed.
## Contributing ## Contributing
1. Create an issue and describe your idea We have collected notes on how to contribute to this project in [CONTRIBUTING.md].
2. [Fork it](https://github.com/skywinder/github-changelog-generator/fork)
3. Create your feature branch (`git checkout -b my-new-feature`)
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Publish the branch (`git push origin my-new-feature`)
6. Create a new Pull Request
7. Profit! :white_check_mark:
You can test your workflow with changelog generator with [the skywinder/changelog_test repo](https://github.com/skywinder/changelog_test/). [CONTRIBUTING.md]: CONTRIBUTING.md
## License ## License

View File

@@ -9,12 +9,11 @@ require "fileutils"
require "overcommit" require "overcommit"
RuboCop::RakeTask.new RuboCop::RakeTask.new
RSpec::Core::RakeTask.new(:rspec) RSpec::Core::RakeTask.new
desc "When releasing the gem, re-fetch latest cacert.pem from curl.haxx.se. Developer task." desc "When releasing the gem, re-fetch latest cacert.pem from curl.haxx.se. Developer task."
task :update_ssl_ca_file do task :update_ssl_ca_file do
`pushd lib/github_changelog_generator/ssl_certs && curl --remote-name --time-cond cacert.pem https://curl.haxx.se/ca/cacert.pem && popd` `pushd lib/github_changelog_generator/ssl_certs && curl --remote-name --time-cond cacert.pem https://curl.haxx.se/ca/cacert.pem && popd`
end end
task checks: %i[rubocop rspec] task default: %i[rubocop spec]
task default: %i[rubocop rspec]

View File

@@ -39,7 +39,7 @@ install:
build_script: build_script:
# Install ruby dependencies # Install ruby dependencies
- bundle install --retry 3 - bundle install --retry 3
- bundle exec rake checks - bundle exec rake
test_script: test_script:
- gem build github_changelog_generator - gem build github_changelog_generator

View File

@@ -24,11 +24,11 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"] spec.require_paths = ["lib"]
spec.add_runtime_dependency "rake", ">= 10.0"
spec.add_runtime_dependency "rainbow", ">= 2.2.1"
spec.add_runtime_dependency("octokit", ["~> 4.6"])
spec.add_runtime_dependency("faraday-http-cache")
spec.add_runtime_dependency("activesupport") spec.add_runtime_dependency("activesupport")
spec.add_runtime_dependency("retriable", ["~> 3.0"]) spec.add_runtime_dependency("faraday-http-cache")
spec.add_runtime_dependency("multi_json") spec.add_runtime_dependency("multi_json")
spec.add_runtime_dependency("octokit", ["~> 4.6"])
spec.add_runtime_dependency "rainbow", ">= 2.2.1"
spec.add_runtime_dependency "rake", ">= 10.0"
spec.add_runtime_dependency("retriable", ["~> 3.0"])
end end

View File

@@ -1,10 +1,10 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative "../octo_fetcher" require "github_changelog_generator/octo_fetcher"
require_relative "generator_generation" require "github_changelog_generator/generator/generator_generation"
require_relative "generator_fetcher" require "github_changelog_generator/generator/generator_fetcher"
require_relative "generator_processor" require "github_changelog_generator/generator/generator_processor"
require_relative "generator_tags" require "github_changelog_generator/generator/generator_tags"
module GitHubChangelogGenerator module GitHubChangelogGenerator
# Default error for ChangelogGenerator # Default error for ChangelogGenerator
@@ -95,12 +95,13 @@ module GitHubChangelogGenerator
# @param [Array] pull_requests # @param [Array] pull_requests
# @return [String] generated log for issues # @return [String] generated log for issues
def issues_to_log(issues, pull_requests) def issues_to_log(issues, pull_requests)
log = "" sections = parse_by_sections(issues, pull_requests)
bugs_a, enhancement_a, issues_a = parse_by_sections(issues, pull_requests)
log += generate_sub_section(enhancement_a, options[:enhancement_prefix]) log = ""
log += generate_sub_section(bugs_a, options[:bug_prefix]) log += generate_sub_section(sections[:breaking], options[:breaking_prefix])
log += generate_sub_section(issues_a, options[:issue_prefix]) log += generate_sub_section(sections[:enhancements], options[:enhancement_prefix])
log += generate_sub_section(sections[:bugs], options[:bug_prefix])
log += generate_sub_section(sections[:issues], options[:issue_prefix])
log log
end end
@@ -109,47 +110,69 @@ module GitHubChangelogGenerator
# #
# @param [Array] issues # @param [Array] issues
# @param [Array] pull_requests # @param [Array] pull_requests
# @return [Array] tuple of filtered arrays: (Bugs, Enhancements Issues) # @return [Hash] Mapping of filtered arrays: (Bugs, Enhancements, Breaking stuff, Issues)
def parse_by_sections(issues, pull_requests) def parse_by_sections(issues, pull_requests)
issues_a = [] sections = {
enhancement_a = [] issues: [],
bugs_a = [] enhancements: [],
bugs: [],
breaking: []
}
issues.each do |dict| issues.each do |dict|
added = false added = false
dict["labels"].each do |label| dict["labels"].each do |label|
if options[:bug_labels].include?(label["name"]) if options[:bug_labels].include?(label["name"])
bugs_a.push(dict) sections[:bugs] << dict
added = true added = true
next elsif options[:enhancement_labels].include?(label["name"])
end sections[:enhancements] << dict
if options[:enhancement_labels].include?(label["name"]) added = true
enhancement_a.push(dict) elsif options[:breaking_labels].include?(label["name"])
sections[:breaking] << dict
added = true added = true
next
end end
break if added
end end
issues_a.push(dict) unless added
sections[:issues] << dict unless added
end end
sort_pull_requests(pull_requests, sections)
end
# This method iterates through PRs and sorts them into sections
#
# @param [Array] pull_requests
# @param [Hash] sections
# @return [Hash] sections
def sort_pull_requests(pull_requests, sections)
added_pull_requests = [] added_pull_requests = []
pull_requests.each do |pr| pull_requests.each do |pr|
added = false
pr["labels"].each do |label| pr["labels"].each do |label|
if options[:bug_labels].include?(label["name"]) if options[:bug_labels].include?(label["name"])
bugs_a.push(pr) sections[:bugs] << pr
added_pull_requests.push(pr) added_pull_requests << pr
next added = true
end elsif options[:enhancement_labels].include?(label["name"])
if options[:enhancement_labels].include?(label["name"]) sections[:enhancements] << pr
enhancement_a.push(pr) added_pull_requests << pr
added_pull_requests.push(pr) added = true
next elsif options[:breaking_labels].include?(label["name"])
sections[:breaking] << pr
added_pull_requests << pr
added = true
end end
break if added
end end
end end
added_pull_requests.each { |p| pull_requests.delete(p) } added_pull_requests.each { |p| pull_requests.delete(p) }
sections
[bugs_a, enhancement_a, issues_a]
end end
end end
end end

View File

@@ -6,6 +6,7 @@ module GitHubChangelogGenerator
# #
# @return [String] Generated change log file # @return [String] Generated change log file
def compound_changelog def compound_changelog
options.load_custom_ruby_files
fetch_and_filter_tags fetch_and_filter_tags
fetch_issues_and_pr fetch_issues_and_pr

View File

@@ -129,7 +129,7 @@ module GitHubChangelogGenerator
if tag if tag
if all_tags.map { |t| t["name"] }.include? tag if all_tags.map { |t| t["name"] }.include? tag
idx = all_tags.index { |t| t["name"] == tag } idx = all_tags.index { |t| t["name"] == tag }
filtered_tags = if idx > 0 filtered_tags = if idx
all_tags[0..idx] all_tags[0..idx]
else else
[] []

View File

@@ -31,21 +31,27 @@ module GitHubChangelogGenerator
@project = @options[:project] @project = @options[:project]
@since = @options[:since] @since = @options[:since]
@http_cache = @options[:http_cache] @http_cache = @options[:http_cache]
if @http_cache @cache_file = nil
@cache_file = @options.fetch(:cache_file) { File.join(Dir.tmpdir, "github-changelog-http-cache") } @cache_log = nil
@cache_log = @options.fetch(:cache_log) { File.join(Dir.tmpdir, "github-changelog-logger.log") } prepare_cache
init_cache
end
@github_token = fetch_github_token
@request_options = { per_page: PER_PAGE_NUMBER }
@github_options = {}
@github_options[:access_token] = @github_token unless @github_token.nil?
@github_options[:api_endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil?
configure_octokit_ssl configure_octokit_ssl
@client = Octokit::Client.new(github_options)
end
@client = Octokit::Client.new(@github_options) def prepare_cache
return unless @http_cache
@cache_file = @options.fetch(:cache_file) { File.join(Dir.tmpdir, "github-changelog-http-cache") }
@cache_log = @options.fetch(:cache_log) { File.join(Dir.tmpdir, "github-changelog-logger.log") }
init_cache
end
def github_options
result = {}
github_token = fetch_github_token
result[:access_token] = github_token if github_token
endpoint = @options[:github_endpoint]
result[:api_endpoint] = endpoint if endpoint
result
end end
def configure_octokit_ssl def configure_octokit_ssl
@@ -54,21 +60,19 @@ module GitHubChangelogGenerator
end end
def init_cache def init_cache
middleware_opts = { Octokit.middleware = Faraday::RackBuilder.new do |builder|
serializer: Marshal, builder.use(Faraday::HttpCache, serializer: Marshal,
store: ActiveSupport::Cache::FileStore.new(@cache_file), store: ActiveSupport::Cache::FileStore.new(@cache_file),
logger: Logger.new(@cache_log), logger: Logger.new(@cache_log),
shared_cache: false shared_cache: false)
}
stack = Faraday::RackBuilder.new do |builder|
builder.use Faraday::HttpCache, middleware_opts
builder.use Octokit::Response::RaiseError builder.use Octokit::Response::RaiseError
builder.adapter Faraday.default_adapter builder.adapter Faraday.default_adapter
# builder.response :logger # builder.response :logger
end end
Octokit.middleware = stack
end end
DEFAULT_REQUEST_OPTIONS = { per_page: PER_PAGE_NUMBER }
# Fetch all tags from repo # Fetch all tags from repo
# #
# @return [Array <Hash>] array of tags # @return [Array <Hash>] array of tags
@@ -84,7 +88,7 @@ module GitHubChangelogGenerator
def calculate_pages(client, method, request_options) def calculate_pages(client, method, request_options)
# Makes the first API call so that we can call last_response # Makes the first API call so that we can call last_response
check_github_response do check_github_response do
client.send(method, user_project, @request_options.merge(request_options)) client.send(method, user_project, DEFAULT_REQUEST_OPTIONS.merge(request_options))
end end
last_response = client.last_response last_response = client.last_response
@@ -104,7 +108,7 @@ module GitHubChangelogGenerator
page_i = 0 page_i = 0
count_pages = calculate_pages(@client, "tags", {}) count_pages = calculate_pages(@client, "tags", {})
iterate_pages(@client, "tags", {}) do |new_tags| iterate_pages(@client, "tags") do |new_tags|
page_i += PER_PAGE_NUMBER page_i += PER_PAGE_NUMBER
print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}") print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
tags.concat(new_tags) tags.concat(new_tags)
@@ -118,8 +122,13 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
Helper.log.info "Found #{tags.count} tags" Helper.log.info "Found #{tags.count} tags"
end end
# tags are a Sawyer::Resource. Convert to hash # tags are a Sawyer::Resource. Convert to hash
tags = tags.map { |h| stringify_keys_deep(h.to_hash) } tags.map { |resource| stringify_keys_deep(resource.to_hash) }
tags end
def closed_pr_options
@closed_pr_options ||= {
filter: "all", labels: nil, state: "closed"
}.tap { |options| options[:since] = @since if @since }
end end
# This method fetch all closed issues and separate them to pull requests and pure issues # This method fetch all closed issues and separate them to pull requests and pure issues
@@ -129,17 +138,10 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
def fetch_closed_issues_and_pr def fetch_closed_issues_and_pr
print "Fetching closed issues...\r" if @options[:verbose] print "Fetching closed issues...\r" if @options[:verbose]
issues = [] issues = []
options = {
state: "closed",
filter: "all",
labels: nil
}
options[:since] = @since unless @since.nil?
page_i = 0 page_i = 0
count_pages = calculate_pages(@client, "issues", options) count_pages = calculate_pages(@client, "issues", closed_pr_options)
iterate_pages(@client, "issues", options) do |new_issues| iterate_pages(@client, "issues", closed_pr_options) do |new_issues|
page_i += PER_PAGE_NUMBER page_i += PER_PAGE_NUMBER
print_in_same_line("Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}") print_in_same_line("Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
issues.concat(new_issues) issues.concat(new_issues)
@@ -148,12 +150,9 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
print_empty_line print_empty_line
Helper.log.info "Received issues: #{issues.count}" Helper.log.info "Received issues: #{issues.count}"
issues = issues.map { |h| stringify_keys_deep(h.to_hash) }
# separate arrays of issues and pull requests: # separate arrays of issues and pull requests:
issues.partition do |x| issues.map { |issue| stringify_keys_deep(issue.to_hash) }
x["pull_request"].nil? .partition { |issue_or_pr| issue_or_pr["pull_request"].nil? }
end
end end
# Fetch all pull requests. We need them to detect :merged_at parameter # Fetch all pull requests. We need them to detect :merged_at parameter
@@ -179,8 +178,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
print_empty_line print_empty_line
Helper.log.info "Pull Request count: #{pull_requests.count}" Helper.log.info "Pull Request count: #{pull_requests.count}"
pull_requests = pull_requests.map { |h| stringify_keys_deep(h.to_hash) } pull_requests.map { |pull_request| stringify_keys_deep(pull_request.to_hash) }
pull_requests
end end
# Fetch event for all issues and add them to 'events' # Fetch event for all issues and add them to 'events'
@@ -195,10 +193,10 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
issues_slice.each do |issue| issues_slice.each do |issue|
threads << Thread.new do threads << Thread.new do
issue["events"] = [] issue["events"] = []
iterate_pages(@client, "issue_events", issue["number"], {}) do |new_event| iterate_pages(@client, "issue_events", issue["number"]) do |new_event|
issue["events"].concat(new_event) issue["events"].concat(new_event)
end end
issue["events"] = issue["events"].map { |h| stringify_keys_deep(h.to_hash) } issue["events"] = issue["events"].map { |event| stringify_keys_deep(event.to_hash) }
print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}") print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}")
i += 1 i += 1
end end
@@ -256,14 +254,15 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
stringify_keys_deep(value) stringify_keys_deep(value)
end end
when Hash when Hash
indata.each_with_object({}) do |(k, v), output| indata.each_with_object({}) do |(key, value), output|
output[k.to_s] = stringify_keys_deep(v) output[key.to_s] = stringify_keys_deep(value)
end end
else else
indata indata
end end
end end
# Exception raised to warn about moved repositories.
MovedPermanentlyError = Class.new(RuntimeError) MovedPermanentlyError = Class.new(RuntimeError)
# Iterates through all pages until there are no more :next pages to follow # Iterates through all pages until there are no more :next pages to follow
@@ -274,29 +273,21 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
# #
# @yield [Sawyer::Resource] An OctoKit-provided response (which can be empty) # @yield [Sawyer::Resource] An OctoKit-provided response (which can be empty)
# #
# @return [Integer] total number of pages # @return [void]
def iterate_pages(client, method, *args) def iterate_pages(client, method, *args)
request_opts = extract_request_args(args) args << DEFAULT_REQUEST_OPTIONS.merge(extract_request_args(args))
args.push(@request_options.merge(request_opts))
number_of_pages = 1
check_github_response { client.send(method, user_project, *args) } check_github_response { client.send(method, user_project, *args) }
last_response = client.last_response last_response = client.last_response.tap do |response|
if last_response.status == 301 raise(MovedPermanentlyError, response.data[:url]) if response.status == 301
raise MovedPermanentlyError, last_response.data[:url]
end end
yield(last_response.data) yield(last_response.data)
until (next_one = last_response.rels[:next]).nil? until (next_one = last_response.rels[:next]).nil?
number_of_pages += 1
last_response = check_github_response { next_one.get } last_response = check_github_response { next_one.get }
yield(last_response.data) yield(last_response.data)
end end
number_of_pages
end end
def extract_request_args(args) def extract_request_args(args)
@@ -317,14 +308,17 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
yield yield
end end
rescue MovedPermanentlyError => e rescue MovedPermanentlyError => e
Helper.log.error("#{e.class}: #{e.message}") fail_with_message(e, "The repository has moved, update your configuration")
sys_abort("The repository has moved, please update your configuration")
rescue Octokit::Forbidden => e rescue Octokit::Forbidden => e
Helper.log.error("#{e.class}: #{e.message}") fail_with_message(e, "Exceeded retry limit")
sys_abort("Exceeded retry limit")
rescue Octokit::Unauthorized => e rescue Octokit::Unauthorized => e
fail_with_message(e, "Error: wrong GitHub token")
end
# Presents the exception, and the aborts with the message.
def fail_with_message(e, message)
Helper.log.error("#{e.class}: #{e.message}") Helper.log.error("#{e.class}: #{e.message}")
sys_abort("Error: wrong GitHub token") sys_abort(message)
end end
# Exponential backoff # Exponential backoff
@@ -373,7 +367,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
# #
# @return [String] # @return [String]
def fetch_github_token def fetch_github_token
env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil) env_var = @options[:token].presence || ENV["CHANGELOG_GITHUB_TOKEN"]
Helper.log.warn NO_TOKEN_PROVIDED unless env_var Helper.log.warn NO_TOKEN_PROVIDED unless env_var

View File

@@ -1,10 +1,17 @@
# frozen_string_literal: true # frozen_string_literal: true
require "delegate" require "delegate"
require "github_changelog_generator/helper"
module GitHubChangelogGenerator module GitHubChangelogGenerator
# This class wraps Options, and knows a list of known options. Others options
# will raise exceptions.
class Options < SimpleDelegator class Options < SimpleDelegator
# Raised on intializing with unknown keys in the values hash,
# and when trying to store a value on an unknown key.
UnsupportedOptionError = Class.new(ArgumentError) UnsupportedOptionError = Class.new(ArgumentError)
# List of valid option names
KNOWN_OPTIONS = %i[ KNOWN_OPTIONS = %i[
add_issues_wo_labels add_issues_wo_labels
add_pr_wo_labels add_pr_wo_labels
@@ -20,13 +27,14 @@ module GitHubChangelogGenerator
due_tag due_tag
enhancement_labels enhancement_labels
enhancement_prefix enhancement_prefix
breaking_labels
breaking_prefix
exclude_labels exclude_labels
exclude_tags exclude_tags
exclude_tags_regex exclude_tags_regex
filter_issues_by_milestone filter_issues_by_milestone
frontmatter frontmatter
future_release future_release
git_remote
github_endpoint github_endpoint
github_site github_site
header header
@@ -42,6 +50,7 @@ module GitHubChangelogGenerator
pulls pulls
release_branch release_branch
release_url release_url
require
simple_list simple_list
since_tag since_tag
ssl_ca_file ssl_ca_file
@@ -54,26 +63,56 @@ module GitHubChangelogGenerator
verbose verbose
] ]
# @param values [Hash]
#
# @raise [UnsupportedOptionError] if given values contain unknown options
def initialize(values) def initialize(values)
super(values) super(values)
unsupported_options.any? && raise(UnsupportedOptionError, unsupported_options.inspect) unsupported_options.any? && raise(UnsupportedOptionError, unsupported_options.inspect)
end end
# Set option key to val.
#
# @param key [Symbol]
# @param val [Object]
#
# @raise [UnsupportedOptionError] when trying to set an unknown option
def []=(key, val) def []=(key, val)
supported_option?(key) || raise(UnsupportedOptionError, key.inspect) supported_option?(key) || raise(UnsupportedOptionError, key.inspect)
values[key] = val values[key] = val
end end
# @return [Hash]
def to_hash def to_hash
values values
end end
# Loads the configured Ruby files from the --require option.
def load_custom_ruby_files
self[:require].each { |f| require f }
end
# Pretty-prints a censored options hash, if :verbose.
def print_options
return unless self[:verbose]
Helper.log.info "Using these options:"
pp(censored_values)
puts ""
end
private private
def values def values
__getobj__ __getobj__
end end
# Returns a censored options hash.
#
# @return [Hash] The GitHub `:token` key is censored in the output.
def censored_values
values.clone.tap { |opts| opts[:token] = opts[:token].nil? ? "No token used" : "hidden value" }
end
def unsupported_options def unsupported_options
values.keys - KNOWN_OPTIONS values.keys - KNOWN_OPTIONS
end end

View File

@@ -3,8 +3,9 @@
require "optparse" require "optparse"
require "pp" require "pp"
require_relative "version" require "github_changelog_generator/version"
require_relative "helper" require "github_changelog_generator/helper"
module GitHubChangelogGenerator module GitHubChangelogGenerator
class Parser class Parser
# parse options with optparse # parse options with optparse
@@ -19,45 +20,34 @@ module GitHubChangelogGenerator
abort [e, parser].join("\n") abort [e, parser].join("\n")
end end
fetch_user_and_project(options) unless options[:user] && options[:project]
warn "Configure which user and project to work on."
warn "Options --user and --project, or settings to that effect. See --help for more."
abort(parser.banner)
end
abort(parser.banner) unless options[:user] && options[:project] options.print_options
print_options(options)
options options
end end
# If options set to verbose, print the parsed options. # Setup parsing options
# #
# The GitHub `:token` key is censored in the output. # @param options [Options]
# # @return [OptionParser]
# @param options [Hash] The options to display
# @option options [Boolean] :verbose If false this method does nothing
def self.print_options(options)
if options[:verbose]
Helper.log.info "Performing task with options:"
options_to_display = options.clone
options_to_display[:token] = options_to_display[:token].nil? ? nil : "hidden value"
pp options_to_display
puts ""
end
end
# setup parsing options
def self.setup_parser(options) def self.setup_parser(options)
parser = OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength
opts.banner = "Usage: github_changelog_generator [options]" opts.banner = "Usage: github_changelog_generator --user USER --project PROJECT [options]"
opts.on("-u", "--user [USER]", "Username of the owner of target GitHub repo") do |last| opts.on("-u", "--user USER", "Username of the owner of target GitHub repo") do |last|
options[:user] = last options[:user] = last
end end
opts.on("-p", "--project [PROJECT]", "Name of project on GitHub") do |last| opts.on("-p", "--project PROJECT", "Name of project on GitHub") do |last|
options[:project] = last options[:project] = last
end end
opts.on("-t", "--token [TOKEN]", "To make more than 50 requests per hour your GitHub token is required. You can generate it at: https://github.com/settings/tokens/new") do |last| opts.on("-t", "--token [TOKEN]", "To make more than 50 requests per hour your GitHub token is required. You can generate it at: https://github.com/settings/tokens/new") do |last|
options[:token] = last options[:token] = last
end end
opts.on("-f", "--date-format [FORMAT]", "Date format. Default is %Y-%m-%d") do |last| opts.on("-f", "--date-format FORMAT", "Date format. Default is %Y-%m-%d") do |last|
options[:date_format] = last options[:date_format] = last
end end
opts.on("-o", "--output [NAME]", "Output file. Default is CHANGELOG.md") do |last| opts.on("-o", "--output [NAME]", "Output file. Default is CHANGELOG.md") do |last|
@@ -72,6 +62,9 @@ module GitHubChangelogGenerator
opts.on("--enhancement-label [LABEL]", "Setup custom label for enhancements section. Default is \"**Implemented enhancements:**\"") do |v| opts.on("--enhancement-label [LABEL]", "Setup custom label for enhancements section. Default is \"**Implemented enhancements:**\"") do |v|
options[:enhancement_prefix] = v options[:enhancement_prefix] = v
end end
opts.on("--breaking-label [LABEL]", "Setup custom label for the breaking changes section. Default is \"**Breaking changes:**\"") do |v|
options[:breaking_prefix] = v
end
opts.on("--issues-label [LABEL]", "Setup custom label for closed-issues section. Default is \"**Closed issues:**\"") do |v| opts.on("--issues-label [LABEL]", "Setup custom label for closed-issues section. Default is \"**Closed issues:**\"") do |v|
options[:issue_prefix] = v options[:issue_prefix] = v
end end
@@ -120,7 +113,7 @@ module GitHubChangelogGenerator
opts.on("--include-labels x,y,z", Array, "Only issues with the specified labels will be included in the changelog.") do |list| opts.on("--include-labels x,y,z", Array, "Only issues with the specified labels will be included in the changelog.") do |list|
options[:include_labels] = list options[:include_labels] = list
end end
opts.on("--exclude-labels x,y,z", Array, 'Issues with the specified labels will be always excluded from changelog. Default is \'duplicate,question,invalid,wontfix\'') do |list| opts.on("--exclude-labels x,y,z", Array, "Issues with the specified labels will be always excluded from changelog. Default is 'duplicate,question,invalid,wontfix'") do |list|
options[:exclude_labels] = list options[:exclude_labels] = list
end end
opts.on("--bug-labels x,y,z", Array, 'Issues with the specified labels will be always added to "Fixed bugs" section. Default is \'bug,Bug\'') do |list| opts.on("--bug-labels x,y,z", Array, 'Issues with the specified labels will be always added to "Fixed bugs" section. Default is \'bug,Bug\'') do |list|
@@ -129,6 +122,9 @@ module GitHubChangelogGenerator
opts.on("--enhancement-labels x,y,z", Array, 'Issues with the specified labels will be always added to "Implemented enhancements" section. Default is \'enhancement,Enhancement\'') do |list| opts.on("--enhancement-labels x,y,z", Array, 'Issues with the specified labels will be always added to "Implemented enhancements" section. Default is \'enhancement,Enhancement\'') do |list|
options[:enhancement_labels] = list options[:enhancement_labels] = list
end end
opts.on("--breaking-labels x,y,z", Array, 'Issues with these labels will be added to a new section, called "Breaking Changes". Default is \'backwards-incompatible\'') do |list|
options[:breaking_labels] = list
end
opts.on("--issue-line-labels x,y,z", Array, 'The specified labels will be shown in brackets next to each matching issue. Use "ALL" to show all labels. Default is [].') do |list| opts.on("--issue-line-labels x,y,z", Array, 'The specified labels will be shown in brackets next to each matching issue. Use "ALL" to show all labels. Default is [].') do |list|
options[:issue_line_labels] = list options[:issue_line_labels] = list
end end
@@ -177,6 +173,9 @@ module GitHubChangelogGenerator
opts.on("--ssl-ca-file [PATH]", "Path to cacert.pem file. Default is a bundled lib/github_changelog_generator/ssl_certs/cacert.pem. Respects SSL_CA_PATH.") do |ssl_ca_file| opts.on("--ssl-ca-file [PATH]", "Path to cacert.pem file. Default is a bundled lib/github_changelog_generator/ssl_certs/cacert.pem. Respects SSL_CA_PATH.") do |ssl_ca_file|
options[:ssl_ca_file] = ssl_ca_file options[:ssl_ca_file] = ssl_ca_file
end end
opts.on("--require x,y,z", Array, "Path to Ruby file(s) to require.") do |paths|
options[:require] = paths
end
opts.on("--[no-]verbose", "Run verbosely. Default is true") do |v| opts.on("--[no-]verbose", "Run verbosely. Default is true") do |v|
options[:verbose] = v options[:verbose] = v
end end
@@ -189,10 +188,9 @@ module GitHubChangelogGenerator
exit exit
end end
end end
parser
end end
# @return [Hash] Default options # @return [Options] Default options
def self.default_options def self.default_options
Options.new( Options.new(
date_format: "%Y-%m-%d", date_format: "%Y-%m-%d",
@@ -210,6 +208,7 @@ module GitHubChangelogGenerator
enhancement_labels: ["enhancement", "Enhancement", "Type: Enhancement"], enhancement_labels: ["enhancement", "Enhancement", "Type: Enhancement"],
bug_labels: ["bug", "Bug", "Type: Bug"], bug_labels: ["bug", "Bug", "Type: Bug"],
exclude_labels: ["duplicate", "question", "invalid", "wontfix", "Duplicate", "Question", "Invalid", "Wontfix", "Meta: Exclude From Changelog"], exclude_labels: ["duplicate", "question", "invalid", "wontfix", "Duplicate", "Question", "Invalid", "Wontfix", "Meta: Exclude From Changelog"],
breaking_labels: %w[backwards-incompatible breaking],
issue_line_labels: [], issue_line_labels: [],
max_issues: nil, max_issues: nil,
simple_list: false, simple_list: false,
@@ -220,114 +219,10 @@ module GitHubChangelogGenerator
issue_prefix: "**Closed issues:**", issue_prefix: "**Closed issues:**",
bug_prefix: "**Fixed bugs:**", bug_prefix: "**Fixed bugs:**",
enhancement_prefix: "**Implemented enhancements:**", enhancement_prefix: "**Implemented enhancements:**",
git_remote: "origin", breaking_prefix: "**Breaking changes:**",
http_cache: true http_cache: true,
require: []
) )
end end
# If `:user` or `:project` not set in options, try setting them
# Valid unnamed parameters:
# 1) in 1 param: repo_name/project
# 2) in 2 params: repo name project
def self.fetch_user_and_project(options)
if options[:user].nil? || options[:project].nil?
user, project = user_and_project_from_git(options, ARGV[0], ARGV[1])
options[:user] ||= user
options[:project] ||= project
end
end
# Sets `:user` and `:project` in `options` from CLI arguments or `git remote`
# @param [String] arg0 first argument in cli
# @param [String] arg1 second argument in cli
# @return [Array<String>] user and project, or nil if unsuccessful
def self.user_and_project_from_git(options, arg0 = nil, arg1 = nil)
user, project = user_project_from_option(arg0, arg1, options[:github_site])
unless user && project
if ENV["RUBYLIB"] =~ /ruby-debug-ide/
user = "skywinder"
project = "changelog_test"
else
remote = `git config --get remote.#{options[:git_remote]}.url`
user, project = user_project_from_remote(remote)
end
end
[user, project]
end
# Returns GitHub username and project from CLI arguments
#
# @param arg0 [String] This parameter takes two forms: Either a full
# GitHub URL, or a 'username/projectname', or
# simply a GitHub username
# @param arg1 [String] If arg0 is given as a username,
# then arg1 can given as a projectname
# @param github_site [String] Domain name of GitHub site
#
# @return [Array, nil] user and project, or nil if unsuccessful
def self.user_project_from_option(arg0, arg1, github_site)
user = nil
project = nil
github_site ||= "github.com"
if arg0 && !arg1
# this match should parse strings such "https://github.com/skywinder/Github-Changelog-Generator" or
# "skywinder/Github-Changelog-Generator" to user and name
match = /(?:.+#{Regexp.escape(github_site)}\/)?(.+)\/(.+)/.match(arg0)
begin
param = match[2].nil?
rescue StandardError
puts "Can't detect user and name from first parameter: '#{arg0}' -> exit'"
return
end
if param
return
else
user = match[1]
project = match[2]
end
end
[user, project]
end
# These patterns match these formats:
#
# ```
# origin git@github.com:skywinder/Github-Changelog-Generator.git (fetch)
# git@github.com:skywinder/Github-Changelog-Generator.git
# ```
#
# and
#
# ```
# origin https://github.com/skywinder/ChangelogMerger (fetch)
# https://github.com/skywinder/ChangelogMerger
# ```
GIT_REMOTE_PATTERNS = [
/.*(?:[:\/])(?<user>(?:-|\w|\.)*)\/(?<project>(?:-|\w|\.)*)(?:\.git).*/,
/.*\/(?<user>(?:-|\w|\.)*)\/(?<project>(?:-|\w|\.)*).*/
]
# Returns GitHub username and project from git remote output
#
# @param git_remote_output [String] Output of git remote command
#
# @return [Array] user and project
def self.user_project_from_remote(git_remote_output)
user = nil
project = nil
GIT_REMOTE_PATTERNS.each do |git_remote_pattern|
git_remote_pattern =~ git_remote_output
if Regexp.last_match
user = Regexp.last_match(:user)
project = Regexp.last_match(:project)
break
end
end
[user, project]
end
end end
end end

View File

@@ -67,7 +67,7 @@ module GitHubChangelogGenerator
end end
KNOWN_ARRAY_KEYS = %i[exclude_labels include_labels bug_labels KNOWN_ARRAY_KEYS = %i[exclude_labels include_labels bug_labels
enhancement_labels issue_line_labels between_tags exclude_tags] enhancement_labels breaking_labels issue_line_labels between_tags exclude_tags]
KNOWN_INTEGER_KEYS = [:max_issues] KNOWN_INTEGER_KEYS = [:max_issues]
def convert_value(value, option_name) def convert_value(value, option_name)
@@ -91,6 +91,7 @@ module GitHubChangelogGenerator
header_label: :header, header_label: :header,
front_matter: :frontmatter, front_matter: :frontmatter,
pr_label: :merge_prefix, pr_label: :merge_prefix,
breaking_label: :breaking_prefix,
issues_wo_labels: :add_issues_wo_labels, issues_wo_labels: :add_issues_wo_labels,
pr_wo_labels: :add_pr_wo_labels, pr_wo_labels: :add_pr_wo_labels,
pull_requests: :pulls, pull_requests: :pulls,

View File

@@ -10,6 +10,7 @@ module GitHubChangelogGenerator
OPTIONS = %w[ user project token date_format output OPTIONS = %w[ user project token date_format output
bug_prefix enhancement_prefix issue_prefix bug_prefix enhancement_prefix issue_prefix
breaking_labels issue_line_labels
header merge_prefix issues header merge_prefix issues
add_issues_wo_labels add_pr_wo_labels add_issues_wo_labels add_pr_wo_labels
pulls filter_issues_by_milestone author pulls filter_issues_by_milestone author
@@ -48,13 +49,11 @@ module GitHubChangelogGenerator
# mimick parse_options # mimick parse_options
options = Parser.default_options options = Parser.default_options
Parser.fetch_user_and_project(options)
OPTIONS.each do |o| OPTIONS.each do |o|
v = instance_variable_get("@#{o}") v = instance_variable_get("@#{o}")
options[o.to_sym] = v unless v.nil? options[o.to_sym] = v unless v.nil?
end end
abort "user and project are required." unless options[:user] && options[:project]
generator = Generator.new options generator = Generator.new options
log = generator.compound_changelog log = generator.compound_changelog

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
module GitHubChangelogGenerator module GitHubChangelogGenerator
VERSION = "1.15.0-alpha" VERSION = "1.15.0-rc"
end end

View File

@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "GIT\-GENERATE\-CHANGELOG" "1" "December 2016" "" "" .TH "GIT\-GENERATE\-CHANGELOG" "1" "October 2017" "" ""
. .
.SH "NAME" .SH "NAME"
\fBgit\-generate\-changelog\fR \- Generate changelog from github \fBgit\-generate\-changelog\fR \- Generate changelog from github
@@ -175,12 +175,6 @@ Issues with the specified labels will be always added to "Fixed bugs" section\.
Issues with the specified labels will be always added to "Implemented enhancements" section\. Default is \'enhancement,Enhancement\' Issues with the specified labels will be always added to "Implemented enhancements" section\. Default is \'enhancement,Enhancement\'
. .
.P .P
\-\-between\-tags x,y,z
.
.P
Change log will be filled only between specified tags
.
.P
\-\-exclude\-tags x,y,z \-\-exclude\-tags x,y,z
. .
.P .P
@@ -264,6 +258,25 @@ Filename to use for cache\. Default is github\-changelog\-http\-cache in a tempo
.P .P
Filename to use for cache log\. Default is github\-changelog\-logger\.log in a temporary directory\. Filename to use for cache log\. Default is github\-changelog\-logger\.log in a temporary directory\.
. .
.IP "" 4
.
.nf
\-\-ssl\-ca\-file [PATH]
.
.fi
.
.IP "" 0
.
.P
Path to cacert\.pem file\. Default is a bundled lib/github_changelog_generator/ssl_certs/cacert\.pem\. Respects SSL_CA_PATH\.
.
.P
\-\-require file1\.rb,file2\.rb
.
.P
Paths to Ruby file(s) to require before generating changelog\.
.
.P .P
\-\-[no\-]verbose \-\-[no\-]verbose
. .

View File

@@ -248,6 +248,15 @@
<p> Filename to use for cache log. Default is github-changelog-logger.log in a temporary directory.</p> <p> Filename to use for cache log. Default is github-changelog-logger.log in a temporary directory.</p>
<pre><code>--ssl-ca-file [PATH]
</code></pre>
<p> Path to cacert.pem file. Default is a bundled lib/github_changelog_generator/ssl_certs/cacert.pem. Respects SSL_CA_PATH.</p>
<p> --require file1.rb,file2.rb</p>
<p> Paths to Ruby file(s) to require before generating changelog.</p>
<p> --[no-]verbose</p> <p> --[no-]verbose</p>
<p> Run verbosely. Default is true</p> <p> Run verbosely. Default is true</p>
@@ -277,7 +286,7 @@
<ol class='man-decor man-foot man foot'> <ol class='man-decor man-foot man foot'>
<li class='tl'></li> <li class='tl'></li>
<li class='tc'>December 2016</li> <li class='tc'>October 2017</li>
<li class='tr'>git-generate-changelog(1)</li> <li class='tr'>git-generate-changelog(1)</li>
</ol> </ol>

View File

@@ -177,7 +177,11 @@ Automatically generate change log from your tags, issues, labels and pull reques
--ssl-ca-file [PATH] --ssl-ca-file [PATH]
Path to cacert.pem file. Default is a bundled lib/github_changelog_generator/ssl_certs/cacert.pem. Respects SSL_CA_PATH. Path to cacert.pem file. Default is a bundled lib/github_changelog_generator/ssl_certs/cacert.pem. Respects SSL_CA_PATH.
--require file1.rb,file2.rb
Paths to Ruby file(s) to require before generating changelog.
--[no-]verbose --[no-]verbose

View File

@@ -13,5 +13,61 @@ module GitHubChangelogGenerator
end.not_to raise_error end.not_to raise_error
end end
end end
describe "#parse_by_sections" do
def label(name)
{ "name" => name }
end
def issue(title, labels)
{ "title" => "issue #{title}", "labels" => labels.map { |l| label(l) } }
end
def pr(title, labels)
{ "title" => "pr #{title}", "labels" => labels.map { |l| label(l) } }
end
def get_titles(issues)
issues.map { |issue| issue["title"] }
end
let(:options) do
{
bug_labels: ["bug"],
enhancement_labels: ["enhancement"],
breaking_labels: ["breaking"]
}
end
let(:issues) do
[
issue("no labels", []),
issue("enhancement", ["enhancement"]),
issue("bug", ["bug"]),
issue("breaking", ["breaking"]),
issue("all the labels", %w[enhancement bug breaking])
]
end
let(:pull_requests) do
[
pr("no labels", []),
pr("enhancement", ["enhancement"]),
pr("bug", ["bug"]),
pr("breaking", ["breaking"]),
pr("all the labels", %w[enhancement bug breaking])
]
end
it "works" do
sections = described_class.new(options).parse_by_sections(issues, pull_requests)
expect(get_titles(sections[:issues])).to eq(["issue no labels"])
expect(get_titles(sections[:enhancements])).to eq(["issue enhancement", "issue all the labels", "pr enhancement", "pr all the labels"])
expect(get_titles(sections[:bugs])).to eq(["issue bug", "pr bug"])
expect(get_titles(sections[:breaking])).to eq(["issue breaking", "pr breaking"])
expect(get_titles(pull_requests)).to eq(["pr no labels"])
end
end
end end
end end

View File

@@ -182,6 +182,11 @@ describe GitHubChangelogGenerator::Generator do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") } let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") }
it { is_expected.to be_a Array } it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_from_strings(%w[1 2])) } it { is_expected.to match_array(tags_from_strings(%w[1 2])) }
context "with since tag set to the most recent tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "1") }
it { is_expected.to match_array(tags_from_strings(%w[1])) }
end
end end
context "with invalid since tag" do context "with invalid since tag" do

View File

@@ -12,7 +12,7 @@ RSpec.describe GitHubChangelogGenerator::Options do
it "raises an error" do it "raises an error" do
expect do expect do
described_class.new( described_class.new(
git_remote: "origin", project: "rails",
strength: "super-strength", strength: "super-strength",
wisdom: "deep" wisdom: "deep"
) )
@@ -22,13 +22,13 @@ RSpec.describe GitHubChangelogGenerator::Options do
end end
describe "#[]=(key, value)" do describe "#[]=(key, value)" do
let(:options) { described_class.new(git_remote: "origin") } let(:options) { described_class.new(project: "rails") }
context "with known options" do context "with known options" do
it "sets the option value" do it "sets the option value" do
expect do expect do
options[:git_remote] = "in the cloud" options[:project] = "trails"
end.to change { options[:git_remote] }.to "in the cloud" end.to change { options[:project] }.to "trails"
end end
end end

View File

@@ -1,83 +1,4 @@
# frozen_string_literal: true # frozen_string_literal: true
describe GitHubChangelogGenerator::Parser do describe GitHubChangelogGenerator::Parser do
describe ".user_project_from_remote" do
context "when remote is type 1" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("origin https://github.com/skywinder/ActionSheetPicker-3.0 (fetch)") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when remote is type 2" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("https://github.com/skywinder/ActionSheetPicker-3.0") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when remote is type 3" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("https://github.com/skywinder/ActionSheetPicker-3.0") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when remote is type 4" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("origin git@github.com:skywinder/ActionSheetPicker-3.0.git (fetch)") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when remote is invalid" do
subject { GitHubChangelogGenerator::Parser.user_project_from_remote("some invalid text") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array([nil, nil]) }
end
end
describe ".user_project_from_option" do
context "when option is invalid" do
it("should return nil") { expect(GitHubChangelogGenerator::Parser.user_project_from_option("blah", nil, nil)).to be_nil }
end
context "when option is valid" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", nil, nil) }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when option nil" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option(nil, nil, nil) }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array([nil, nil]) }
end
context "when site is nil" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", nil, nil) }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when site is valid" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", nil, "https://codeclimate.com") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array(["skywinder", "ActionSheetPicker-3.0"]) }
end
context "when second arg is not nil" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", "blah", nil) }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array([nil, nil]) }
end
context "when all args is not nil" do
subject { GitHubChangelogGenerator::Parser.user_project_from_option("skywinder/ActionSheetPicker-3.0", "blah", "https://codeclimate.com") }
it { is_expected.to be_a(Array) }
it { is_expected.to match_array([nil, nil]) }
end
end
describe ".fetch_user_and_project" do
before do
stub_const("ARGV", ["https://github.com/skywinder/github-changelog-generator"])
end
context do
let(:valid_user) { "initialized_user" }
let(:options) { { user: valid_user } }
let(:options_before_change) { options.dup }
it "should leave user unchanged" do
expect { GitHubChangelogGenerator::Parser.fetch_user_and_project(options) }.to change { options }
.from(options_before_change)
.to(options_before_change.merge(project: "github-changelog-generator"))
end
end
end
end end