ParserFile: Allow comments in settings file
- Ruby-style or semi-colon-style accepted
This commit is contained in:
parent
c5a92b71b2
commit
4569fad479
|
@ -7,11 +7,13 @@ module GitHubChangelogGenerator
|
||||||
# given Hash.
|
# given Hash.
|
||||||
#
|
#
|
||||||
# In your project's root, you can put a file named
|
# In your project's root, you can put a file named
|
||||||
# <tt>.github_changelog_generator</tt> to override defaults:
|
# <tt>.github_changelog_generator</tt> to override defaults.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# header_label=# My Super Changelog
|
# header_label=# My Super Changelog
|
||||||
|
# ; Comments are allowed
|
||||||
# future-release=5.0.0
|
# future-release=5.0.0
|
||||||
|
# # Ruby-style comments, too
|
||||||
# since-tag=1.0.0
|
# since-tag=1.0.0
|
||||||
#
|
#
|
||||||
# The configuration format is <tt>some-key=value</tt> or <tt>some_key=value</tt>.
|
# The configuration format is <tt>some-key=value</tt> or <tt>some_key=value</tt>.
|
||||||
|
@ -41,12 +43,18 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_line!(line, line_number)
|
def parse_line!(line, line_number)
|
||||||
|
return if non_configuration_line?(line)
|
||||||
option_name, value = extract_pair(line)
|
option_name, value = extract_pair(line)
|
||||||
@options[option_key_for(option_name)] = convert_value(value, option_name)
|
@options[option_key_for(option_name)] = convert_value(value, option_name)
|
||||||
rescue
|
rescue
|
||||||
raise ParserError, "Failed on line ##{line_number}: \"#{line.gsub(/[\n\r]+/, '')}\""
|
raise ParserError, "Failed on line ##{line_number}: \"#{line.gsub(/[\n\r]+/, '')}\""
|
||||||
end
|
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.
|
# Returns a the option name as a symbol and its string value sans newlines.
|
||||||
#
|
#
|
||||||
# @param line [String] unparsed line from config file
|
# @param line [String] unparsed line from config file
|
||||||
|
|
|
@ -26,6 +26,14 @@ describe GitHubChangelogGenerator::ParserFile do
|
||||||
it { expect { parser.parse! }.to raise_error(/line #2/) }
|
it { expect { parser.parse! }.to raise_error(/line #2/) }
|
||||||
end
|
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
|
context "when override default values" do
|
||||||
let(:default_options) { GitHubChangelogGenerator::Parser.default_options }
|
let(:default_options) { GitHubChangelogGenerator::Parser.default_options }
|
||||||
let(:options) { {}.merge(default_options) }
|
let(:options) { {}.merge(default_options) }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user