From 44bbd9ca01aa15df7a7b78da545f5f2c2529fc5d Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 17 Mar 2016 20:39:49 +0100 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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