Compare commits

..

13 Commits

Author SHA1 Message Date
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
19 changed files with 277 additions and 311 deletions

View File

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

View File

@@ -4,6 +4,7 @@ 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.8
install: true # This skips 'bundle install' install: true # This skips 'bundle install'
@@ -18,14 +19,6 @@ matrix:
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:

View File

@@ -1,5 +1,68 @@
# Change Log # Change Log
## [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) ([thebyt3](https://github.com/thebyt3))
- 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)

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)*
@@ -71,32 +76,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 +110,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 +148,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 +159,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,12 +187,14 @@ 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.

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

@@ -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
issues_a.push(dict) unless added
end end
break if added
end
sections[:issues] << dict unless added
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

@@ -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_log = nil
prepare_cache
configure_octokit_ssl
@client = Octokit::Client.new(github_options)
end
def prepare_cache
return unless @http_cache
@cache_file = @options.fetch(:cache_file) { File.join(Dir.tmpdir, "github-changelog-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") } @cache_log = @options.fetch(:cache_log) { File.join(Dir.tmpdir, "github-changelog-logger.log") }
init_cache init_cache
end end
@github_token = fetch_github_token
@request_options = { per_page: PER_PAGE_NUMBER } def github_options
@github_options = {} result = {}
@github_options[:access_token] = @github_token unless @github_token.nil? github_token = fetch_github_token
@github_options[:api_endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil? result[:access_token] = github_token if github_token
endpoint = @options[:github_endpoint]
configure_octokit_ssl result[:api_endpoint] = endpoint if endpoint
result
@client = Octokit::Client.new(@github_options)
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

@@ -20,13 +20,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

View File

@@ -19,8 +19,6 @@ module GitHubChangelogGenerator
abort [e, parser].join("\n") abort [e, parser].join("\n")
end end
fetch_user_and_project(options)
abort(parser.banner) unless options[:user] && options[:project] abort(parser.banner) unless options[:user] && options[:project]
print_options(options) print_options(options)
@@ -72,6 +70,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
@@ -129,6 +130,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
@@ -210,6 +214,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 +225,9 @@ 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
) )
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

@@ -48,13 +48,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-beta"
end end

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