From 9cb03fa7459b53f4a121cf15997b178f2998a70d Mon Sep 17 00:00:00 2001 From: Landon Abney Date: Fri, 4 Mar 2016 13:40:56 -0800 Subject: [PATCH 01/22] Add an AppVeyor config --- appveyor.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..dbd2114 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,50 @@ +version: "{build}" + +platform: x64 + +branches: + only: + - master + +clone_depth: 10 + +skip_tags: true + +# See here for Ruby versions pre-installed: +# http://www.appveyor.com/docs/installed-software#ruby +environment: + matrix: + - ruby_version: "21" # Older version, but matches Travis-CI + - ruby_version: "21-x64" + +install: + - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% + + # Print version and location for pre-installed ruby + - ruby --version + - where ruby + + # Install latest version of RubyGems + - gem update --system --no-document --no-post-install-message + - gem --version + - where gem + + # Print version and location for pre-installed bundler + - bundler --version + - where bundler + +build_script: + # Install ruby dependencies + - bundle install --retry 3 + - bundle exec rake checks + +test_script: + - gem build github_changelog_generator + - gem install *.gem + +notifications: + - provider: Email + to: + - sky4winder+githubchangeloggenerator@gmail.com + on_build_success: false + on_build_status_changed: true From a7ee304f20e1d133e5a9b66a81873344b474fd12 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Wed, 9 Mar 2016 10:37:13 -0800 Subject: [PATCH 02/22] Add bundle install test --- .gitignore | 6 ++++++ .travis.yml | 9 +++++++-- Gemfile.lock | 16 ++++++++-------- spec/install-gem-in-bundler.gemfile | 3 +++ 4 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 spec/install-gem-in-bundler.gemfile diff --git a/.gitignore b/.gitignore index 404abb2..1abe828 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ +bin/ +!bin/git-generate-changelog +!bin/github_changelog_generator +pkg/ coverage/ +.bundle +spec/*.lock diff --git a/.travis.yml b/.travis.yml index c17e5d4..b171cfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ -sudo: false +cache: + - bundler language: ruby before_install: - gem update --system - gem install bundler rvm: - - 2.1.0 + - 2.1 script: bundle exec rake checks matrix: include: @@ -13,6 +14,10 @@ matrix: script: - gem build github_changelog_generator - gem install *.gem + - install: true + script: + - gem build github_changelog_generator + - bundle install --gemfile spec/install-gem-in-bundler.gemfile notifications: email: recipients: diff --git a/Gemfile.lock b/Gemfile.lock index 1f3be29..8bfbb1c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,10 +17,10 @@ GEM ast (2.2.0) childprocess (0.5.9) ffi (~> 1.0, >= 1.0.11) - codeclimate-test-reporter (0.4.8) + codeclimate-test-reporter (0.5.0) simplecov (>= 0.7.1, < 1.0.0) colorize (0.7.7) - coveralls (0.8.11) + coveralls (0.8.13) json (~> 1.8) simplecov (~> 0.11.0) term-ansicolor (~> 1.3) @@ -61,12 +61,12 @@ GEM powerpack (0.1.1) rack (1.6.4) rainbow (2.1.0) - rake (10.5.0) + rake (11.0.1) rspec (3.4.0) rspec-core (~> 3.4.0) rspec-expectations (~> 3.4.0) rspec-mocks (~> 3.4.0) - rspec-core (3.4.3) + rspec-core (3.4.4) rspec-support (~> 3.4.0) rspec-expectations (3.4.0) diff-lcs (>= 1.2.0, < 2.0) @@ -75,12 +75,12 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.4.0) rspec-support (3.4.1) - rubocop (0.37.2) - parser (>= 2.3.0.4, < 3.0) + rubocop (0.38.0) + parser (>= 2.3.0.6, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 0.3) + unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.7.5) simplecov (0.11.2) docile (~> 1.1.0) @@ -92,7 +92,7 @@ GEM thor (0.19.1) thread_safe (0.3.5) tins (1.6.0) - unicode-display_width (0.3.1) + unicode-display_width (1.0.1) PLATFORMS ruby diff --git a/spec/install-gem-in-bundler.gemfile b/spec/install-gem-in-bundler.gemfile new file mode 100644 index 0000000..85493a9 --- /dev/null +++ b/spec/install-gem-in-bundler.gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gem "github_changelog_generator", path: Dir.glob("../pkg/github_changelog_generator-*.gem")[0] From 44bbd9ca01aa15df7a7b78da545f5f2c2529fc5d Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 17 Mar 2016 20:39:49 +0100 Subject: [PATCH 03/22] Parse options file options - this proof-of-concept code duplicates OptionParser information to get something going - take care to respect the type of each option from the OptionParser --- lib/github_changelog_generator/parser_file.rb | 22 ++++++++++++++++--- spec/unit/parse_file_spec.rb | 1 - 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index 3bf505f..1dbae70 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -23,9 +23,7 @@ module GitHubChangelogGenerator def parse_line!(line) key_sym, value = extract_pair(line) - value = true if value =~ /^(true|t|yes|y|1)$/i - value = false if value =~ /^(false|f|no|n|0)$/i - @options[key_sym] = value + @options[key_sym] = convert_value(value, key_sym) rescue raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\"" end @@ -38,5 +36,23 @@ module GitHubChangelogGenerator key, value = line.split("=", 2) [key.sub("-", "_").to_sym, value.gsub(/[\n\r]+/, "")] end + + KNOWN_ARRAY_KEYS = [:exclude_labels, :include_labels, :bug_labels, + :enhancement_labels, :between_tags, :exclude_tags] + KNOWN_INTEGER_KEYS = [:max_issues] + + def convert_value(value, key_sym) + if KNOWN_ARRAY_KEYS.include?(key_sym) + value.split(",") + elsif KNOWN_INTEGER_KEYS.include?(key_sym) + value.to_i + elsif value =~ /^(true|t|yes|y|1)$/i + true + elsif value =~ /^(false|f|no|n|0)$/i + false + else + value + end + end end end diff --git a/spec/unit/parse_file_spec.rb b/spec/unit/parse_file_spec.rb index f130d34..99c6477 100644 --- a/spec/unit/parse_file_spec.rb +++ b/spec/unit/parse_file_spec.rb @@ -44,7 +44,6 @@ describe GitHubChangelogGenerator::ParserFile do } end it "reads exclude_labels into an Array" do - pending("Related with Bug #327.") expect { parse.parse! }.to change { options[:exclude_labels] } .from(nil) .to(["73a91042-da6f-11e5-9335-1040f38d7f90", "7adf83b4-da6f-11e5-ae18-1040f38d7f90"]) From d0bd44e0c8c56280cf45534f8e2eb3388eeb721b Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 17 Mar 2016 21:08:17 +0100 Subject: [PATCH 04/22] Translate option names --- lib/github_changelog_generator/parser_file.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index 1dbae70..81272cf 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -23,7 +23,7 @@ module GitHubChangelogGenerator def parse_line!(line) key_sym, value = extract_pair(line) - @options[key_sym] = convert_value(value, key_sym) + @options[translate_option_name(key_sym)] = convert_value(value, key_sym) rescue raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\"" end @@ -54,5 +54,21 @@ module GitHubChangelogGenerator value end end + + def translate_option_name(key_sym) + { + bugs_label: :bug_prefix, + enhancement_label: :enhancement_prefix, + issues_label: :issue_prefix, + header_label: :header, + front_matter: :frontmatter, + pr_label: :merge_prefix, + issues_wo_labels: :add_issues_wo_labels, + pr_wo_labels: :add_pr_wo_labels, + pull_requests: :pulls, + filter_by_milestone: :filter_issues_by_milestone, + github_api: :github_endpoint + }.fetch(key_sym) { key_sym } + end end end From 655aa965a73f18ae1e0ce3fca6cf69389f7375b5 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 17 Mar 2016 21:38:28 +0100 Subject: [PATCH 05/22] Spec: option name translation tested --- spec/files/github_changelog_params_327 | 3 ++- spec/unit/parse_file_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/files/github_changelog_params_327 b/spec/files/github_changelog_params_327 index 21fce1c..2506a61 100644 --- a/spec/files/github_changelog_params_327 +++ b/spec/files/github_changelog_params_327 @@ -1 +1,2 @@ -exclude-labels=73a91042-da6f-11e5-9335-1040f38d7f90,7adf83b4-da6f-11e5-ae18-1040f38d7f90 \ No newline at end of file +exclude-labels=73a91042-da6f-11e5-9335-1040f38d7f90,7adf83b4-da6f-11e5-ae18-1040f38d7f90 +header_label=# My changelog diff --git a/spec/unit/parse_file_spec.rb b/spec/unit/parse_file_spec.rb index 99c6477..2e4f1a6 100644 --- a/spec/unit/parse_file_spec.rb +++ b/spec/unit/parse_file_spec.rb @@ -43,11 +43,18 @@ describe GitHubChangelogGenerator::ParserFile do params_file: "spec/files/github_changelog_params_327" } end + it "reads exclude_labels into an Array" do expect { parse.parse! }.to change { options[:exclude_labels] } .from(nil) .to(["73a91042-da6f-11e5-9335-1040f38d7f90", "7adf83b4-da6f-11e5-ae18-1040f38d7f90"]) end + + it "translates given header_label into the :header option" do + expect { parse.parse! }.to change { options[:header] } + .from(nil) + .to("# My changelog") + end end end end From 1519d16cefb14df285ea5563f8db95c0549f5303 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 17 Mar 2016 21:50:14 +0100 Subject: [PATCH 06/22] README: only document how to use &scopes=repo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 27e9188..9275b8c 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Therefore, it's recommended to run this script with authentication by using a ** Here's how: -- [Generate a token here](https://github.com/settings/tokens/new?description=GitHub%20Changelog%20Generator%20token) +- [Generate a token here](https://github.com/settings/tokens/new?description=GitHub%20Changelog%20Generator%20token) - you only need "repo" scope for private repositories - Either: - Run the script with `--token `; **OR** - Set the `CHANGELOG_GITHUB_TOKEN` environment variable to your 40 digit token From 5071b596d2a74942e70cc5ee5aca2b738a4875d0 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 09:40:42 +0100 Subject: [PATCH 07/22] Refactor: call it option_name - also, add a IRREGULAR_OPTIONS hash --- lib/github_changelog_generator/parser_file.rb | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index 81272cf..40c2498 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -22,13 +22,13 @@ module GitHubChangelogGenerator end def parse_line!(line) - key_sym, value = extract_pair(line) - @options[translate_option_name(key_sym)] = convert_value(value, key_sym) + option_name, value = extract_pair(line) + @options[option_key_for(option_name)] = convert_value(value, option_name) rescue raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\"" end - # Returns a the setting as a symbol and its string value sans newlines. + # Returns a the option name as a symbol and its string value sans newlines. # # @param line [String] unparsed line from config file # @return [Array] @@ -41,10 +41,10 @@ module GitHubChangelogGenerator :enhancement_labels, :between_tags, :exclude_tags] KNOWN_INTEGER_KEYS = [:max_issues] - def convert_value(value, key_sym) - if KNOWN_ARRAY_KEYS.include?(key_sym) + def convert_value(value, option_name) + if KNOWN_ARRAY_KEYS.include?(option_name) value.split(",") - elsif KNOWN_INTEGER_KEYS.include?(key_sym) + elsif KNOWN_INTEGER_KEYS.include?(option_name) value.to_i elsif value =~ /^(true|t|yes|y|1)$/i true @@ -55,20 +55,22 @@ module GitHubChangelogGenerator end end - def translate_option_name(key_sym) - { - bugs_label: :bug_prefix, - enhancement_label: :enhancement_prefix, - issues_label: :issue_prefix, - header_label: :header, - front_matter: :frontmatter, - pr_label: :merge_prefix, - issues_wo_labels: :add_issues_wo_labels, - pr_wo_labels: :add_pr_wo_labels, - pull_requests: :pulls, - filter_by_milestone: :filter_issues_by_milestone, - github_api: :github_endpoint - }.fetch(key_sym) { key_sym } + IRREGULAR_OPTIONS = { + bugs_label: :bug_prefix, + enhancement_label: :enhancement_prefix, + issues_label: :issue_prefix, + header_label: :header, + front_matter: :frontmatter, + pr_label: :merge_prefix, + issues_wo_labels: :add_issues_wo_labels, + pr_wo_labels: :add_pr_wo_labels, + pull_requests: :pulls, + filter_by_milestone: :filter_issues_by_milestone, + github_api: :github_endpoint + } + + def option_key_for(option_name) + IRREGULAR_OPTIONS.fetch(option_name) { option_name } end end end From deba7efa49c85ebbc2c94677317d7b62d2c0e6ba Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 10:30:33 +0100 Subject: [PATCH 08/22] On install, do not try to copy manpage files --- github_changelog_generator.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/github_changelog_generator.gemspec b/github_changelog_generator.gemspec index 331f210..694f2c9 100644 --- a/github_changelog_generator.gemspec +++ b/github_changelog_generator.gemspec @@ -16,7 +16,6 @@ Gem::Specification.new do |spec| spec.description = "Changelog generation has never been so easy. Fully automate changelog generation - this gem generate change log file based on tags, issues and merged pull requests from Github issue tracker." spec.homepage = "https://github.com/skywinder/Github-Changelog-Generator" spec.license = "MIT" - spec.extensions = ["Rakefile"] spec.files = `git ls-files -z`.split("\x0") spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } From 93df2d56465fb658305e4b31e721fe5bfa10783f Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 13:59:58 +0100 Subject: [PATCH 09/22] ParserFile: use a File instead of a filename - spec: can use StringIOs instead of loose files --- lib/github_changelog_generator/parser_file.rb | 23 ++++++++++---- spec/files/github_changelog_params_327 | 2 -- spec/files/github_changelog_params_empty | 0 spec/files/github_changelog_params_incorrect | 2 -- spec/files/github_changelog_params_override | 3 -- spec/unit/parse_file_spec.rb | 31 +++++++++++-------- 6 files changed, 35 insertions(+), 26 deletions(-) delete mode 100644 spec/files/github_changelog_params_327 delete mode 100644 spec/files/github_changelog_params_empty delete mode 100644 spec/files/github_changelog_params_incorrect delete mode 100644 spec/files/github_changelog_params_override diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index 40c2498..a85d969 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -6,21 +6,32 @@ module GitHubChangelogGenerator class ParserFile FILENAME = ".github_changelog_generator" - def initialize(options) + attr_reader :file + + # @param options [Hash] + # @param file [nil,IO] + def initialize(options, file = read_default_file) @options = options + @file = file + end + + def read_default_file + File.open(path) if path.exist? + end + + def path + @path ||= Pathname(File.expand_path(FILENAME)) end # Destructively change @options using data in configured options file. def parse! - file.each_line { |line| parse_line!(line) } if file.exist? + return unless file + file.each_line { |line| parse_line!(line) } + file.close end private - def file - @file ||= Pathname(File.expand_path(@options[:params_file] || FILENAME)) - end - def parse_line!(line) option_name, value = extract_pair(line) @options[option_key_for(option_name)] = convert_value(value, option_name) diff --git a/spec/files/github_changelog_params_327 b/spec/files/github_changelog_params_327 deleted file mode 100644 index 2506a61..0000000 --- a/spec/files/github_changelog_params_327 +++ /dev/null @@ -1,2 +0,0 @@ -exclude-labels=73a91042-da6f-11e5-9335-1040f38d7f90,7adf83b4-da6f-11e5-ae18-1040f38d7f90 -header_label=# My changelog diff --git a/spec/files/github_changelog_params_empty b/spec/files/github_changelog_params_empty deleted file mode 100644 index e69de29..0000000 diff --git a/spec/files/github_changelog_params_incorrect b/spec/files/github_changelog_params_incorrect deleted file mode 100644 index 35fa3d8..0000000 --- a/spec/files/github_changelog_params_incorrect +++ /dev/null @@ -1,2 +0,0 @@ -unreleased_label: staging -unreleased: false diff --git a/spec/files/github_changelog_params_override b/spec/files/github_changelog_params_override deleted file mode 100644 index c31e411..0000000 --- a/spec/files/github_changelog_params_override +++ /dev/null @@ -1,3 +0,0 @@ -unreleased_label=staging -unreleased=false -header==== Changelog === diff --git a/spec/unit/parse_file_spec.rb b/spec/unit/parse_file_spec.rb index 2e4f1a6..24171fc 100644 --- a/spec/unit/parse_file_spec.rb +++ b/spec/unit/parse_file_spec.rb @@ -8,8 +8,8 @@ describe GitHubChangelogGenerator::ParserFile do end context "when file is empty" do - let(:options) { { params_file: "spec/files/github_changelog_params_empty" } } - let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) } + let(:options) { {} } + let(:parse) { GitHubChangelogGenerator::ParserFile.new(options, StringIO.new("")) } it "does not change the options" do expect { parse.parse! }.to_not change { options } @@ -17,17 +17,21 @@ describe GitHubChangelogGenerator::ParserFile do end context "when file is incorrect" do - let(:options) { { params_file: "spec/files/github_changelog_params_incorrect" } } + let(:options) { {} } let(:options_before_change) { options.dup } - let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) } + let(:file) { StringIO.new("unreleased_label: staging\nunreleased: false") } + let(:parse) do + GitHubChangelogGenerator::ParserFile.new(options, file) + end it { expect { parse.parse! }.to raise_error(GitHubChangelogGenerator::ParserError) } end context "when override default values" do let(:default_options) { GitHubChangelogGenerator::Parser.default_options } - let(:options) { { params_file: "spec/files/github_changelog_params_override" }.merge(default_options) } + let(:options) { {}.merge(default_options) } let(:options_before_change) { options.dup } - let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) } + let(:file) { StringIO.new("unreleased_label=staging\nunreleased=false\nheader==== Changelog ===") } + let(:parse) { GitHubChangelogGenerator::ParserFile.new(options, file) } it "changes the options" do expect { parse.parse! }.to change { options } @@ -38,21 +42,22 @@ describe GitHubChangelogGenerator::ParserFile do end context "turns exclude-labels into an Array", bug: '#327' do - let(:options) do - { - params_file: "spec/files/github_changelog_params_327" - } + let(:file) do + StringIO.new(< Date: Sat, 19 Mar 2016 15:09:08 +0100 Subject: [PATCH 10/22] ParserFile: Drop unused public method --- lib/github_changelog_generator/parser_file.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index a85d969..0fc58e9 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -16,14 +16,11 @@ module GitHubChangelogGenerator end def read_default_file + path = Pathname(File.expand_path(FILENAME)) File.open(path) if path.exist? end - def path - @path ||= Pathname(File.expand_path(FILENAME)) - end - - # Destructively change @options using data in configured options file. + # Set @options using configuration file lines. def parse! return unless file file.each_line { |line| parse_line!(line) } From 2e8e2a62e18317b37a99c469c9322c8fabf9a885 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 15:13:12 +0100 Subject: [PATCH 11/22] ParserFile: removed public method --- lib/github_changelog_generator/parser_file.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index 0fc58e9..da50af1 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -6,8 +6,6 @@ module GitHubChangelogGenerator class ParserFile FILENAME = ".github_changelog_generator" - attr_reader :file - # @param options [Hash] # @param file [nil,IO] def initialize(options, file = read_default_file) @@ -22,9 +20,9 @@ module GitHubChangelogGenerator # Set @options using configuration file lines. def parse! - return unless file - file.each_line { |line| parse_line!(line) } - file.close + return unless @file + @file.each_line { |line| parse_line!(line) } + @file.close end private @@ -33,7 +31,7 @@ module GitHubChangelogGenerator option_name, value = extract_pair(line) @options[option_key_for(option_name)] = convert_value(value, option_name) rescue - raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\"" + raise ParserError, "Config file problem on line \"#{line.gsub(/[\n\r]+/, '')}\"" end # Returns a the option name as a symbol and its string value sans newlines. From 29b5ef3d53926734bffe23c900be75bfe0ac0227 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 15:18:20 +0100 Subject: [PATCH 12/22] ParserFile: config failure line number --- lib/github_changelog_generator/parser_file.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index da50af1..c36b6ae 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -21,17 +21,17 @@ module GitHubChangelogGenerator # Set @options using configuration file lines. def parse! return unless @file - @file.each_line { |line| parse_line!(line) } + @file.each_with_index { |line, i| parse_line!(line, i + 1) } @file.close end private - def parse_line!(line) + def parse_line!(line, line_number) option_name, value = extract_pair(line) @options[option_key_for(option_name)] = convert_value(value, option_name) rescue - raise ParserError, "Config file problem on line \"#{line.gsub(/[\n\r]+/, '')}\"" + raise ParserError, "Config file parsing failed on line ##{line_number}: \"#{line.gsub(/[\n\r]+/, '')}\"" end # Returns a the option name as a symbol and its string value sans newlines. From a997d2417d71bf92c438627b8110a2e8aff68314 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 15:20:48 +0100 Subject: [PATCH 13/22] Spec: Config parse fail message tested --- spec/unit/parse_file_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/parse_file_spec.rb b/spec/unit/parse_file_spec.rb index 24171fc..5eac4c4 100644 --- a/spec/unit/parse_file_spec.rb +++ b/spec/unit/parse_file_spec.rb @@ -19,11 +19,11 @@ describe GitHubChangelogGenerator::ParserFile do context "when file is incorrect" do let(:options) { {} } let(:options_before_change) { options.dup } - let(:file) { StringIO.new("unreleased_label: staging\nunreleased: false") } + let(:file) { StringIO.new("unreleased_label=staging\nunreleased: false") } let(:parse) do GitHubChangelogGenerator::ParserFile.new(options, file) end - it { expect { parse.parse! }.to raise_error(GitHubChangelogGenerator::ParserError) } + it { expect { parse.parse! }.to raise_error(/line #2/) } end context "when override default values" do From 0b3248418441ac68a09621e49a61052800a06e4b Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 15:22:45 +0100 Subject: [PATCH 14/22] Spec: rename local to noun --- spec/unit/parse_file_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/unit/parse_file_spec.rb b/spec/unit/parse_file_spec.rb index 5eac4c4..735f32e 100644 --- a/spec/unit/parse_file_spec.rb +++ b/spec/unit/parse_file_spec.rb @@ -2,17 +2,17 @@ describe GitHubChangelogGenerator::ParserFile do describe ".github_changelog_generator" do context "when no has file" do let(:options) { {} } - let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) } - subject { parse.parse! } + let(:parser) { GitHubChangelogGenerator::ParserFile.new(options) } + subject { parser.parse! } it { is_expected.to be_nil } end context "when file is empty" do let(:options) { {} } - let(:parse) { GitHubChangelogGenerator::ParserFile.new(options, StringIO.new("")) } + let(:parser) { GitHubChangelogGenerator::ParserFile.new(options, StringIO.new("")) } it "does not change the options" do - expect { parse.parse! }.to_not change { options } + expect { parser.parse! }.to_not change { options } end end @@ -20,10 +20,10 @@ describe GitHubChangelogGenerator::ParserFile do let(:options) { {} } let(:options_before_change) { options.dup } let(:file) { StringIO.new("unreleased_label=staging\nunreleased: false") } - let(:parse) do + let(:parser) do GitHubChangelogGenerator::ParserFile.new(options, file) end - it { expect { parse.parse! }.to raise_error(/line #2/) } + it { expect { parser.parse! }.to raise_error(/line #2/) } end context "when override default values" do @@ -31,10 +31,10 @@ describe GitHubChangelogGenerator::ParserFile do let(:options) { {}.merge(default_options) } let(:options_before_change) { options.dup } let(:file) { StringIO.new("unreleased_label=staging\nunreleased=false\nheader==== Changelog ===") } - let(:parse) { GitHubChangelogGenerator::ParserFile.new(options, file) } + let(:parser) { GitHubChangelogGenerator::ParserFile.new(options, file) } it "changes the options" do - expect { parse.parse! }.to change { options } + expect { parser.parse! }.to change { options } .from(options_before_change) .to(options_before_change.merge(unreleased_label: "staging", unreleased: false, @@ -50,13 +50,13 @@ EOF ) end it "reads exclude_labels into an Array" do - expect { parse.parse! }.to change { options[:exclude_labels] } + expect { parser.parse! }.to change { options[:exclude_labels] } .from(default_options[:exclude_labels]) .to(["73a91042-da6f-11e5-9335-1040f38d7f90", "7adf83b4-da6f-11e5-ae18-1040f38d7f90"]) end it "translates given header_label into the :header option" do - expect { parse.parse! }.to change { options[:header] } + expect { parser.parse! }.to change { options[:header] } .from(default_options[:header]) .to("# My changelog") end From 6b64d4e4a20e55be2d7b9bca70335d29f6310c11 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 15:50:05 +0100 Subject: [PATCH 15/22] Docs --- lib/github_changelog_generator/parser_file.rb | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index c36b6ae..d71a71b 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -3,22 +3,28 @@ require "pathname" module GitHubChangelogGenerator ParserError = Class.new(StandardError) + # ParserFile is a configuration file reader which sets options in the + # given Hash. + # + # In your project's root, you can put a file named + # .github_changelog_generator to override defaults: + # + # Example: + # header_label=# My Super Changelog + # future-release=5.0.0 + # since-tag=1.0.0 + # + # The configuration format is some-key=value or some_key=value. + # class ParserFile - FILENAME = ".github_changelog_generator" - - # @param options [Hash] - # @param file [nil,IO] + # @param options [Hash] options to be configured from file contents + # @param file [nil,IO] configuration file handle, defaults to opening `.github_changelog_generator` def initialize(options, file = read_default_file) @options = options @file = file end - def read_default_file - path = Pathname(File.expand_path(FILENAME)) - File.open(path) if path.exist? - end - - # Set @options using configuration file lines. + # Sets options using configuration file content def parse! return unless @file @file.each_with_index { |line, i| parse_line!(line, i + 1) } @@ -27,6 +33,13 @@ module GitHubChangelogGenerator private + FILENAME = ".github_changelog_generator" + + def read_default_file + path = Pathname(File.expand_path(FILENAME)) + File.open(path) if path.exist? + end + def parse_line!(line, line_number) option_name, value = extract_pair(line) @options[option_key_for(option_name)] = convert_value(value, option_name) From 1a289c872dd8172ba71ed760f3b13cf3313df533 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 16:09:34 +0100 Subject: [PATCH 16/22] ParserFile: rename private method --- lib/github_changelog_generator/parser_file.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index d71a71b..f5097d4 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -19,7 +19,7 @@ module GitHubChangelogGenerator class ParserFile # @param options [Hash] options to be configured from file contents # @param file [nil,IO] configuration file handle, defaults to opening `.github_changelog_generator` - def initialize(options, file = read_default_file) + def initialize(options, file = open_settings_file) @options = options @file = file end @@ -35,7 +35,7 @@ module GitHubChangelogGenerator FILENAME = ".github_changelog_generator" - def read_default_file + def open_settings_file path = Pathname(File.expand_path(FILENAME)) File.open(path) if path.exist? end From 7c2b95d24b48fcdbb2a675eb44abfe2567d8e0d3 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 16:17:10 +0100 Subject: [PATCH 17/22] ParserFile: shorter error message due to context --- lib/github_changelog_generator/parser_file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index f5097d4..d08ddfe 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -44,7 +44,7 @@ module GitHubChangelogGenerator option_name, value = extract_pair(line) @options[option_key_for(option_name)] = convert_value(value, option_name) rescue - raise ParserError, "Config file parsing failed on line ##{line_number}: \"#{line.gsub(/[\n\r]+/, '')}\"" + raise ParserError, "Failed on line ##{line_number}: \"#{line.gsub(/[\n\r]+/, '')}\"" end # Returns a the option name as a symbol and its string value sans newlines. From 4569fad479ebd8dd47782240afbf6bfce6b139ac Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 16:42:36 +0100 Subject: [PATCH 18/22] ParserFile: Allow comments in settings file - Ruby-style or semi-colon-style accepted --- lib/github_changelog_generator/parser_file.rb | 10 +++++++++- spec/unit/parse_file_spec.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index d08ddfe..ec7ee2b 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -7,11 +7,13 @@ module GitHubChangelogGenerator # given Hash. # # In your project's root, you can put a file named - # .github_changelog_generator to override defaults: + # .github_changelog_generator to override defaults. # # Example: # header_label=# My Super Changelog + # ; Comments are allowed # future-release=5.0.0 + # # Ruby-style comments, too # since-tag=1.0.0 # # The configuration format is some-key=value or some_key=value. @@ -41,12 +43,18 @@ module GitHubChangelogGenerator end def parse_line!(line, line_number) + return if non_configuration_line?(line) option_name, value = extract_pair(line) @options[option_key_for(option_name)] = convert_value(value, option_name) rescue raise ParserError, "Failed on line ##{line_number}: \"#{line.gsub(/[\n\r]+/, '')}\"" end + # Returns true if the line starts with a pound sign or a semi-colon. + def non_configuration_line?(line) + line =~ /^[\#;]/ + end + # Returns a the option name as a symbol and its string value sans newlines. # # @param line [String] unparsed line from config file diff --git a/spec/unit/parse_file_spec.rb b/spec/unit/parse_file_spec.rb index 735f32e..65ff5a2 100644 --- a/spec/unit/parse_file_spec.rb +++ b/spec/unit/parse_file_spec.rb @@ -26,6 +26,14 @@ describe GitHubChangelogGenerator::ParserFile do it { expect { parser.parse! }.to raise_error(/line #2/) } end + context "allows comments with semi-colon or pound sign" do + let(:file) { StringIO.new("# Comment on first line\nunreleased_label=staging\n; Comment on third line\nunreleased=false") } + let(:parser) do + GitHubChangelogGenerator::ParserFile.new({}, file) + end + it { expect { parser.parse! }.not_to raise_error } + end + context "when override default values" do let(:default_options) { GitHubChangelogGenerator::Parser.default_options } let(:options) { {}.merge(default_options) } From 068af037f5e9ade5db91aa6371165369ee3ff673 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 16:54:13 +0100 Subject: [PATCH 19/22] Spec: use RSpec contexts --- spec/unit/parse_file_spec.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/unit/parse_file_spec.rb b/spec/unit/parse_file_spec.rb index 65ff5a2..0af43cc 100644 --- a/spec/unit/parse_file_spec.rb +++ b/spec/unit/parse_file_spec.rb @@ -1,14 +1,14 @@ describe GitHubChangelogGenerator::ParserFile do describe ".github_changelog_generator" do - context "when no has file" do - let(:options) { {} } + let(:options) { {} } + + context "when the well-known default file does not exist" do let(:parser) { GitHubChangelogGenerator::ParserFile.new(options) } subject { parser.parse! } it { is_expected.to be_nil } end context "when file is empty" do - let(:options) { {} } let(:parser) { GitHubChangelogGenerator::ParserFile.new(options, StringIO.new("")) } it "does not change the options" do @@ -17,7 +17,6 @@ describe GitHubChangelogGenerator::ParserFile do end context "when file is incorrect" do - let(:options) { {} } let(:options_before_change) { options.dup } let(:file) { StringIO.new("unreleased_label=staging\nunreleased: false") } let(:parser) do @@ -29,7 +28,7 @@ describe GitHubChangelogGenerator::ParserFile do context "allows comments with semi-colon or pound sign" do let(:file) { StringIO.new("# Comment on first line\nunreleased_label=staging\n; Comment on third line\nunreleased=false") } let(:parser) do - GitHubChangelogGenerator::ParserFile.new({}, file) + GitHubChangelogGenerator::ParserFile.new(options, file) end it { expect { parser.parse! }.not_to raise_error } end From 0fccc4396f9f345c6f2320df9984abdb2bb70271 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 17:12:30 +0100 Subject: [PATCH 20/22] ParserFile: Config format allows empty lines - defined as: lines that consist only of whitespace --- lib/github_changelog_generator/parser_file.rb | 2 +- spec/unit/parse_file_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index ec7ee2b..4f7bbfa 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -52,7 +52,7 @@ module GitHubChangelogGenerator # Returns true if the line starts with a pound sign or a semi-colon. def non_configuration_line?(line) - line =~ /^[\#;]/ + line =~ /^[\#;]/ || line =~ /^[\s]+$/ end # Returns a the option name as a symbol and its string value sans newlines. diff --git a/spec/unit/parse_file_spec.rb b/spec/unit/parse_file_spec.rb index 0af43cc..832904a 100644 --- a/spec/unit/parse_file_spec.rb +++ b/spec/unit/parse_file_spec.rb @@ -25,8 +25,8 @@ describe GitHubChangelogGenerator::ParserFile do it { expect { parser.parse! }.to raise_error(/line #2/) } end - context "allows comments with semi-colon or pound sign" do - let(:file) { StringIO.new("# Comment on first line\nunreleased_label=staging\n; Comment on third line\nunreleased=false") } + context "allows empty lines and comments with semi-colon or pound sign" do + let(:file) { StringIO.new("\n \n# Comment on first line\nunreleased_label=staging\n; Comment on third line\nunreleased=false") } let(:parser) do GitHubChangelogGenerator::ParserFile.new(options, file) end From 170eb40f3397d9008ad0b66c69077222aa7dd3f9 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Mon, 21 Mar 2016 22:40:24 +0100 Subject: [PATCH 21/22] Replace shelling-out-to-Git w/ Dir call --- github_changelog_generator.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/github_changelog_generator.gemspec b/github_changelog_generator.gemspec index 331f210..46f7c63 100644 --- a/github_changelog_generator.gemspec +++ b/github_changelog_generator.gemspec @@ -18,7 +18,8 @@ Gem::Specification.new do |spec| spec.license = "MIT" spec.extensions = ["Rakefile"] - spec.files = `git ls-files -z`.split("\x0") + spec.files = Dir['{bin,lib,man,spec}/**/*', 'Rakefile', 'README.md'] + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] From cdc971e86f16778ec2a86e5aea5b6e461462161d Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 22 Mar 2016 14:38:49 +0200 Subject: [PATCH 22/22] Update changelog for version 1.11.8 --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42963c5..dc9093a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # Change Log +## [1.11.8](https://github.com/skywinder/github-changelog-generator/tree/1.11.8) (2016-03-22) +[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/1.11.7...1.11.8) + +**Implemented enhancements:** + +- ParserFile: Allow comments in settings file [\#358](https://github.com/skywinder/github-changelog-generator/pull/358) ([olleolleolle](https://github.com/olleolleolle)) + +**Fixed bugs:** + +- Error when specifying exclude\_labels [\#327](https://github.com/skywinder/github-changelog-generator/issues/327) +- Parse options file options into arrays, integers, flags, and other [\#354](https://github.com/skywinder/github-changelog-generator/pull/354) ([olleolleolle](https://github.com/olleolleolle)) + +**Closed issues:** + +- Installation fails on Ubuntu [\#352](https://github.com/skywinder/github-changelog-generator/issues/352) +- Test installing on Windows: use AppVeyor [\#348](https://github.com/skywinder/github-changelog-generator/issues/348) +- Can't run under RubyGems 2.5.1 and Ruby 2.3.0 [\#325](https://github.com/skywinder/github-changelog-generator/issues/325) +- Ruby 2.3.0 - Deprecation warning: Github::ResponseWrapper\#respond\_to?\(:to\_ary\) is old fashion which takes only one parameter [\#323](https://github.com/skywinder/github-changelog-generator/issues/323) +- between-tags and exclude-tags do not work in .github\_changelog\_generator [\#317](https://github.com/skywinder/github-changelog-generator/issues/317) +- Add a "documentation" label [\#284](https://github.com/skywinder/github-changelog-generator/issues/284) + +**Merged pull requests:** + +- Replace shelling-out-to-Git w/ Dir call [\#360](https://github.com/skywinder/github-changelog-generator/pull/360) ([olleolleolle](https://github.com/olleolleolle)) +- ParserFile: fail parsing with config file line number; use a File instead of a filename [\#357](https://github.com/skywinder/github-changelog-generator/pull/357) ([olleolleolle](https://github.com/olleolleolle)) +- On gem install, do not try to copy manpage files in the "extensions" step [\#356](https://github.com/skywinder/github-changelog-generator/pull/356) ([olleolleolle](https://github.com/olleolleolle)) +- Refactor: call it option\_name, instead of key\_sym [\#355](https://github.com/skywinder/github-changelog-generator/pull/355) ([olleolleolle](https://github.com/olleolleolle)) +- Add a `bundle install` test [\#353](https://github.com/skywinder/github-changelog-generator/pull/353) ([jkeiser](https://github.com/jkeiser)) +- Add an AppVeyor config [\#350](https://github.com/skywinder/github-changelog-generator/pull/350) ([Arcanemagus](https://github.com/Arcanemagus)) +- README: Document GitHub token URI scope [\#345](https://github.com/skywinder/github-changelog-generator/pull/345) ([olleolleolle](https://github.com/olleolleolle)) + ## [1.11.7](https://github.com/skywinder/github-changelog-generator/tree/1.11.7) (2016-03-04) [Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/1.11.6...1.11.7)