Compare commits
13 Commits
v1.15.0.pr
...
v1.15.0.pr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d16bf4cfaa | ||
|
|
fe7c585ed1 | ||
|
|
3f8fb60af3 | ||
|
|
23b341f715 | ||
|
|
630b8cee88 | ||
|
|
74fdc2026a | ||
|
|
21ec2db39b | ||
|
|
d1e09f6964 | ||
|
|
b36d85eb53 | ||
|
|
1658b41dff | ||
|
|
64f4cd07c9 | ||
|
|
7cbe41555a | ||
|
|
dd956b7b95 |
2
.github_changelog_generator
Normal file
2
.github_changelog_generator
Normal file
@@ -0,0 +1,2 @@
|
||||
project=github-changelog-generator
|
||||
user=skywinder
|
||||
@@ -4,6 +4,7 @@ cache:
|
||||
before_install:
|
||||
- gem install bundler
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- rvm: 2.2.8
|
||||
install: true # This skips 'bundle install'
|
||||
@@ -18,14 +19,6 @@ matrix:
|
||||
jdk: oraclejdk8
|
||||
env:
|
||||
- JRUBY_OPTS=--debug
|
||||
- rvm: jruby-head
|
||||
jdk: oraclejdk8
|
||||
env:
|
||||
- JRUBY_OPTS=--debug
|
||||
- DEBUG=1
|
||||
allow_failures:
|
||||
- rvm: jruby-head
|
||||
fast_finish: true
|
||||
|
||||
addons:
|
||||
code_climate:
|
||||
|
||||
63
CHANGELOG.md
63
CHANGELOG.md
@@ -1,5 +1,68 @@
|
||||
# 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)
|
||||
[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/v1.14.2...v1.14.3)
|
||||
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,5 +1,5 @@
|
||||
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:
|
||||
|
||||
|
||||
30
README.md
30
README.md
@@ -30,9 +30,14 @@ GitHub Changelog Generator 
|
||||
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:
|
||||
|
||||
### *What’s 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.
|
||||
|
||||
### *Why should I care?*
|
||||
Because software tools are for people. If you don’t 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)*
|
||||
|
||||
@@ -71,32 +76,31 @@ See also Troubleshooting.
|
||||
|
||||
|
||||
## 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 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-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
|
||||
|
||||
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)
|
||||
|
||||
### Params File
|
||||
|
||||
In your project root, you can put a params file named `.github_changelog_generator` to override default params:
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
unreleased=false
|
||||
future-release=5.0.0
|
||||
@@ -106,6 +110,7 @@ since-tag=1.0.0
|
||||
### GitHub token
|
||||
|
||||
GitHub only allows 50 unauthenticated requests per hour.
|
||||
|
||||
Therefore, it's recommended to run this script with authentication by using a **token**.
|
||||
|
||||
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:
|
||||
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
|
||||
require 'github_changelog_generator/task'
|
||||
@@ -154,11 +159,14 @@ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
||||
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.
|
||||
|
||||
## Features and advantages of this project
|
||||
|
||||
- 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:
|
||||
- **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
|
||||
|
||||
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!*
|
||||
|
||||
|
||||
### Projects using this library
|
||||
|
||||
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.
|
||||
|
||||
5
Rakefile
5
Rakefile
@@ -9,12 +9,11 @@ require "fileutils"
|
||||
require "overcommit"
|
||||
|
||||
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."
|
||||
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`
|
||||
end
|
||||
|
||||
task checks: %i[rubocop rspec]
|
||||
task default: %i[rubocop rspec]
|
||||
task default: %i[rubocop spec]
|
||||
|
||||
@@ -39,7 +39,7 @@ install:
|
||||
build_script:
|
||||
# Install ruby dependencies
|
||||
- bundle install --retry 3
|
||||
- bundle exec rake checks
|
||||
- bundle exec rake
|
||||
|
||||
test_script:
|
||||
- gem build github_changelog_generator
|
||||
|
||||
@@ -95,12 +95,13 @@ module GitHubChangelogGenerator
|
||||
# @param [Array] pull_requests
|
||||
# @return [String] generated log for issues
|
||||
def issues_to_log(issues, pull_requests)
|
||||
log = ""
|
||||
bugs_a, enhancement_a, issues_a = parse_by_sections(issues, pull_requests)
|
||||
sections = parse_by_sections(issues, pull_requests)
|
||||
|
||||
log += generate_sub_section(enhancement_a, options[:enhancement_prefix])
|
||||
log += generate_sub_section(bugs_a, options[:bug_prefix])
|
||||
log += generate_sub_section(issues_a, options[:issue_prefix])
|
||||
log = ""
|
||||
log += generate_sub_section(sections[:breaking], options[:breaking_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
|
||||
end
|
||||
|
||||
@@ -109,47 +110,69 @@ module GitHubChangelogGenerator
|
||||
#
|
||||
# @param [Array] issues
|
||||
# @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)
|
||||
issues_a = []
|
||||
enhancement_a = []
|
||||
bugs_a = []
|
||||
sections = {
|
||||
issues: [],
|
||||
enhancements: [],
|
||||
bugs: [],
|
||||
breaking: []
|
||||
}
|
||||
|
||||
issues.each do |dict|
|
||||
added = false
|
||||
|
||||
dict["labels"].each do |label|
|
||||
if options[:bug_labels].include?(label["name"])
|
||||
bugs_a.push(dict)
|
||||
sections[:bugs] << dict
|
||||
added = true
|
||||
next
|
||||
end
|
||||
if options[:enhancement_labels].include?(label["name"])
|
||||
enhancement_a.push(dict)
|
||||
elsif options[:enhancement_labels].include?(label["name"])
|
||||
sections[:enhancements] << dict
|
||||
added = true
|
||||
elsif options[:breaking_labels].include?(label["name"])
|
||||
sections[:breaking] << dict
|
||||
added = true
|
||||
next
|
||||
end
|
||||
|
||||
break if added
|
||||
end
|
||||
issues_a.push(dict) unless added
|
||||
|
||||
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 = []
|
||||
pull_requests.each do |pr|
|
||||
added = false
|
||||
|
||||
pr["labels"].each do |label|
|
||||
if options[:bug_labels].include?(label["name"])
|
||||
bugs_a.push(pr)
|
||||
added_pull_requests.push(pr)
|
||||
next
|
||||
end
|
||||
if options[:enhancement_labels].include?(label["name"])
|
||||
enhancement_a.push(pr)
|
||||
added_pull_requests.push(pr)
|
||||
next
|
||||
sections[:bugs] << pr
|
||||
added_pull_requests << pr
|
||||
added = true
|
||||
elsif options[:enhancement_labels].include?(label["name"])
|
||||
sections[:enhancements] << pr
|
||||
added_pull_requests << pr
|
||||
added = true
|
||||
elsif options[:breaking_labels].include?(label["name"])
|
||||
sections[:breaking] << pr
|
||||
added_pull_requests << pr
|
||||
added = true
|
||||
end
|
||||
|
||||
break if added
|
||||
end
|
||||
end
|
||||
added_pull_requests.each { |p| pull_requests.delete(p) }
|
||||
|
||||
[bugs_a, enhancement_a, issues_a]
|
||||
sections
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -129,7 +129,7 @@ module GitHubChangelogGenerator
|
||||
if tag
|
||||
if all_tags.map { |t| t["name"] }.include? tag
|
||||
idx = all_tags.index { |t| t["name"] == tag }
|
||||
filtered_tags = if idx > 0
|
||||
filtered_tags = if idx
|
||||
all_tags[0..idx]
|
||||
else
|
||||
[]
|
||||
|
||||
@@ -31,21 +31,27 @@ module GitHubChangelogGenerator
|
||||
@project = @options[:project]
|
||||
@since = @options[:since]
|
||||
@http_cache = @options[:http_cache]
|
||||
if @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
|
||||
@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?
|
||||
|
||||
@cache_file = nil
|
||||
@cache_log = nil
|
||||
prepare_cache
|
||||
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
|
||||
|
||||
def configure_octokit_ssl
|
||||
@@ -54,21 +60,19 @@ module GitHubChangelogGenerator
|
||||
end
|
||||
|
||||
def init_cache
|
||||
middleware_opts = {
|
||||
serializer: Marshal,
|
||||
store: ActiveSupport::Cache::FileStore.new(@cache_file),
|
||||
logger: Logger.new(@cache_log),
|
||||
shared_cache: false
|
||||
}
|
||||
stack = Faraday::RackBuilder.new do |builder|
|
||||
builder.use Faraday::HttpCache, middleware_opts
|
||||
Octokit.middleware = Faraday::RackBuilder.new do |builder|
|
||||
builder.use(Faraday::HttpCache, serializer: Marshal,
|
||||
store: ActiveSupport::Cache::FileStore.new(@cache_file),
|
||||
logger: Logger.new(@cache_log),
|
||||
shared_cache: false)
|
||||
builder.use Octokit::Response::RaiseError
|
||||
builder.adapter Faraday.default_adapter
|
||||
# builder.response :logger
|
||||
end
|
||||
Octokit.middleware = stack
|
||||
end
|
||||
|
||||
DEFAULT_REQUEST_OPTIONS = { per_page: PER_PAGE_NUMBER }
|
||||
|
||||
# Fetch all tags from repo
|
||||
#
|
||||
# @return [Array <Hash>] array of tags
|
||||
@@ -84,7 +88,7 @@ module GitHubChangelogGenerator
|
||||
def calculate_pages(client, method, request_options)
|
||||
# Makes the first API call so that we can call last_response
|
||||
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
|
||||
|
||||
last_response = client.last_response
|
||||
@@ -104,7 +108,7 @@ module GitHubChangelogGenerator
|
||||
page_i = 0
|
||||
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
|
||||
print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
|
||||
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"
|
||||
end
|
||||
# tags are a Sawyer::Resource. Convert to hash
|
||||
tags = tags.map { |h| stringify_keys_deep(h.to_hash) }
|
||||
tags
|
||||
tags.map { |resource| stringify_keys_deep(resource.to_hash) }
|
||||
end
|
||||
|
||||
def closed_pr_options
|
||||
@closed_pr_options ||= {
|
||||
filter: "all", labels: nil, state: "closed"
|
||||
}.tap { |options| options[:since] = @since if @since }
|
||||
end
|
||||
|
||||
# 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
|
||||
print "Fetching closed issues...\r" if @options[:verbose]
|
||||
issues = []
|
||||
options = {
|
||||
state: "closed",
|
||||
filter: "all",
|
||||
labels: nil
|
||||
}
|
||||
options[:since] = @since unless @since.nil?
|
||||
|
||||
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
|
||||
print_in_same_line("Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
|
||||
issues.concat(new_issues)
|
||||
@@ -148,12 +150,9 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
|
||||
print_empty_line
|
||||
Helper.log.info "Received issues: #{issues.count}"
|
||||
|
||||
issues = issues.map { |h| stringify_keys_deep(h.to_hash) }
|
||||
|
||||
# separate arrays of issues and pull requests:
|
||||
issues.partition do |x|
|
||||
x["pull_request"].nil?
|
||||
end
|
||||
issues.map { |issue| stringify_keys_deep(issue.to_hash) }
|
||||
.partition { |issue_or_pr| issue_or_pr["pull_request"].nil? }
|
||||
end
|
||||
|
||||
# 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
|
||||
|
||||
Helper.log.info "Pull Request count: #{pull_requests.count}"
|
||||
pull_requests = pull_requests.map { |h| stringify_keys_deep(h.to_hash) }
|
||||
pull_requests
|
||||
pull_requests.map { |pull_request| stringify_keys_deep(pull_request.to_hash) }
|
||||
end
|
||||
|
||||
# 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|
|
||||
threads << Thread.new do
|
||||
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)
|
||||
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}")
|
||||
i += 1
|
||||
end
|
||||
@@ -256,14 +254,15 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
|
||||
stringify_keys_deep(value)
|
||||
end
|
||||
when Hash
|
||||
indata.each_with_object({}) do |(k, v), output|
|
||||
output[k.to_s] = stringify_keys_deep(v)
|
||||
indata.each_with_object({}) do |(key, value), output|
|
||||
output[key.to_s] = stringify_keys_deep(value)
|
||||
end
|
||||
else
|
||||
indata
|
||||
end
|
||||
end
|
||||
|
||||
# Exception raised to warn about moved repositories.
|
||||
MovedPermanentlyError = Class.new(RuntimeError)
|
||||
|
||||
# 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)
|
||||
#
|
||||
# @return [Integer] total number of pages
|
||||
# @return [void]
|
||||
def iterate_pages(client, method, *args)
|
||||
request_opts = extract_request_args(args)
|
||||
args.push(@request_options.merge(request_opts))
|
||||
|
||||
number_of_pages = 1
|
||||
args << DEFAULT_REQUEST_OPTIONS.merge(extract_request_args(args))
|
||||
|
||||
check_github_response { client.send(method, user_project, *args) }
|
||||
last_response = client.last_response
|
||||
if last_response.status == 301
|
||||
raise MovedPermanentlyError, last_response.data[:url]
|
||||
last_response = client.last_response.tap do |response|
|
||||
raise(MovedPermanentlyError, response.data[:url]) if response.status == 301
|
||||
end
|
||||
|
||||
yield(last_response.data)
|
||||
|
||||
until (next_one = last_response.rels[:next]).nil?
|
||||
number_of_pages += 1
|
||||
|
||||
last_response = check_github_response { next_one.get }
|
||||
yield(last_response.data)
|
||||
end
|
||||
|
||||
number_of_pages
|
||||
end
|
||||
|
||||
def extract_request_args(args)
|
||||
@@ -317,14 +308,17 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
|
||||
yield
|
||||
end
|
||||
rescue MovedPermanentlyError => e
|
||||
Helper.log.error("#{e.class}: #{e.message}")
|
||||
sys_abort("The repository has moved, please update your configuration")
|
||||
fail_with_message(e, "The repository has moved, update your configuration")
|
||||
rescue Octokit::Forbidden => e
|
||||
Helper.log.error("#{e.class}: #{e.message}")
|
||||
sys_abort("Exceeded retry limit")
|
||||
fail_with_message(e, "Exceeded retry limit")
|
||||
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}")
|
||||
sys_abort("Error: wrong GitHub token")
|
||||
sys_abort(message)
|
||||
end
|
||||
|
||||
# Exponential backoff
|
||||
@@ -373,7 +367,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
|
||||
#
|
||||
# @return [String]
|
||||
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
|
||||
|
||||
|
||||
@@ -20,13 +20,14 @@ module GitHubChangelogGenerator
|
||||
due_tag
|
||||
enhancement_labels
|
||||
enhancement_prefix
|
||||
breaking_labels
|
||||
breaking_prefix
|
||||
exclude_labels
|
||||
exclude_tags
|
||||
exclude_tags_regex
|
||||
filter_issues_by_milestone
|
||||
frontmatter
|
||||
future_release
|
||||
git_remote
|
||||
github_endpoint
|
||||
github_site
|
||||
header
|
||||
|
||||
@@ -19,8 +19,6 @@ module GitHubChangelogGenerator
|
||||
abort [e, parser].join("\n")
|
||||
end
|
||||
|
||||
fetch_user_and_project(options)
|
||||
|
||||
abort(parser.banner) unless options[:user] && options[:project]
|
||||
|
||||
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|
|
||||
options[:enhancement_prefix] = v
|
||||
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|
|
||||
options[:issue_prefix] = v
|
||||
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|
|
||||
options[:enhancement_labels] = list
|
||||
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|
|
||||
options[:issue_line_labels] = list
|
||||
end
|
||||
@@ -210,6 +214,7 @@ module GitHubChangelogGenerator
|
||||
enhancement_labels: ["enhancement", "Enhancement", "Type: Enhancement"],
|
||||
bug_labels: ["bug", "Bug", "Type: Bug"],
|
||||
exclude_labels: ["duplicate", "question", "invalid", "wontfix", "Duplicate", "Question", "Invalid", "Wontfix", "Meta: Exclude From Changelog"],
|
||||
breaking_labels: %w[backwards-incompatible breaking],
|
||||
issue_line_labels: [],
|
||||
max_issues: nil,
|
||||
simple_list: false,
|
||||
@@ -220,114 +225,9 @@ module GitHubChangelogGenerator
|
||||
issue_prefix: "**Closed issues:**",
|
||||
bug_prefix: "**Fixed bugs:**",
|
||||
enhancement_prefix: "**Implemented enhancements:**",
|
||||
git_remote: "origin",
|
||||
breaking_prefix: "**Breaking changes:**",
|
||||
http_cache: true
|
||||
)
|
||||
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
|
||||
|
||||
@@ -67,7 +67,7 @@ module GitHubChangelogGenerator
|
||||
end
|
||||
|
||||
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]
|
||||
|
||||
def convert_value(value, option_name)
|
||||
@@ -91,6 +91,7 @@ module GitHubChangelogGenerator
|
||||
header_label: :header,
|
||||
front_matter: :frontmatter,
|
||||
pr_label: :merge_prefix,
|
||||
breaking_label: :breaking_prefix,
|
||||
issues_wo_labels: :add_issues_wo_labels,
|
||||
pr_wo_labels: :add_pr_wo_labels,
|
||||
pull_requests: :pulls,
|
||||
|
||||
@@ -48,13 +48,11 @@ module GitHubChangelogGenerator
|
||||
# mimick parse_options
|
||||
options = Parser.default_options
|
||||
|
||||
Parser.fetch_user_and_project(options)
|
||||
|
||||
OPTIONS.each do |o|
|
||||
v = instance_variable_get("@#{o}")
|
||||
options[o.to_sym] = v unless v.nil?
|
||||
end
|
||||
|
||||
abort "user and project are required." unless options[:user] && options[:project]
|
||||
generator = Generator.new options
|
||||
|
||||
log = generator.compound_changelog
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module GitHubChangelogGenerator
|
||||
VERSION = "1.15.0-alpha"
|
||||
VERSION = "1.15.0-beta"
|
||||
end
|
||||
|
||||
@@ -13,5 +13,61 @@ module GitHubChangelogGenerator
|
||||
end.not_to raise_error
|
||||
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
|
||||
|
||||
@@ -182,6 +182,11 @@ describe GitHubChangelogGenerator::Generator do
|
||||
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") }
|
||||
it { is_expected.to be_a Array }
|
||||
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
|
||||
|
||||
context "with invalid since tag" do
|
||||
|
||||
@@ -12,7 +12,7 @@ RSpec.describe GitHubChangelogGenerator::Options do
|
||||
it "raises an error" do
|
||||
expect do
|
||||
described_class.new(
|
||||
git_remote: "origin",
|
||||
project: "rails",
|
||||
strength: "super-strength",
|
||||
wisdom: "deep"
|
||||
)
|
||||
@@ -22,13 +22,13 @@ RSpec.describe GitHubChangelogGenerator::Options do
|
||||
end
|
||||
|
||||
describe "#[]=(key, value)" do
|
||||
let(:options) { described_class.new(git_remote: "origin") }
|
||||
let(:options) { described_class.new(project: "rails") }
|
||||
|
||||
context "with known options" do
|
||||
it "sets the option value" do
|
||||
expect do
|
||||
options[:git_remote] = "in the cloud"
|
||||
end.to change { options[:git_remote] }.to "in the cloud"
|
||||
options[:project] = "trails"
|
||||
end.to change { options[:project] }.to "trails"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,83 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user