Merge pull request #358 from olleolleolle/feature/parserfile-allow-comments
ParserFile: Allow comments in settings file
This commit is contained in:
commit
6d9fcf202e
|
@ -7,11 +7,13 @@ module GitHubChangelogGenerator
|
|||
# given Hash.
|
||||
#
|
||||
# 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:
|
||||
# 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 <tt>some-key=value</tt> or <tt>some_key=value</tt>.
|
||||
|
@ -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 =~ /^[\#;]/ || line =~ /^[\s]+$/
|
||||
end
|
||||
|
||||
# Returns a the option name as a symbol and its string value sans newlines.
|
||||
#
|
||||
# @param line [String] unparsed line from config file
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
describe GitHubChangelogGenerator::ParserFile do
|
||||
describe ".github_changelog_generator" do
|
||||
context "when no has file" do
|
||||
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
|
||||
|
@ -26,6 +25,14 @@ describe GitHubChangelogGenerator::ParserFile do
|
|||
it { expect { parser.parse! }.to raise_error(/line #2/) }
|
||||
end
|
||||
|
||||
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
|
||||
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) }
|
||||
|
|
Loading…
Reference in New Issue
Block a user