From 4569fad479ebd8dd47782240afbf6bfce6b139ac Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 16:42:36 +0100 Subject: [PATCH] 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) }