From d227464c33ddb2fb738aecf2c64b74975b94f68c Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Wed, 21 Oct 2015 23:42:33 +0200 Subject: [PATCH 1/2] Rubocop: less complex methods - Changed one thing: failed return value on printing the banner when no user or project was found. --- lib/github_changelog_generator/parser.rb | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 5001ad6..502b6d6 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -9,20 +9,14 @@ module GitHubChangelogGenerator def self.parse_options options = get_default_options - parser_file = ParserFile.new options - parser_file.parse! + ParserFile.new(options).parse! parser = setup_parser(options) parser.parse! - if options[:user].nil? || options[:project].nil? - detect_user_and_project(options, ARGV[0], ARGV[1]) - end + user_and_project_from_git(options) - if !options[:user] || !options[:project] - puts parser.banner - exit - end + abort(parser.banner) unless options[:user] && options[:project] print_options(options) @@ -198,17 +192,23 @@ module GitHubChangelogGenerator options end + def self.user_and_project_from_git + if options[:user].nil? || options[:project].nil? + detect_user_and_project(options, ARGV[0], ARGV[1]) + end + end + # Detects user and project from git def self.detect_user_and_project(options, arg0 = nil, arg1 = nil) options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site]) - if !options[:user] || !options[:project] - if ENV["RUBYLIB"] =~ /ruby-debug-ide/ - options[:user] = "skywinder" - options[:project] = "changelog_test" - else - remote = `git config --get remote.#{options[:git_remote]}.url` - options[:user], options[:project] = user_project_from_remote(remote) - end + return if options[:user] && options[:project] + + if ENV["RUBYLIB"] =~ /ruby-debug-ide/ + options[:user] = "skywinder" + options[:project] = "changelog_test" + else + remote = `git config --get remote.#{options[:git_remote]}.url` + options[:user], options[:project] = user_project_from_remote(remote) end end From 3fb75c825fe1b995309a44b09526fd149028f9e1 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 22 Oct 2015 00:09:25 +0200 Subject: [PATCH 2/2] Lint: rename to avoid getter naming - fixed Rake task, too --- lib/github_changelog_generator/parser.rb | 8 +++----- lib/github_changelog_generator/task.rb | 6 ++---- spec/unit/parse_file_spec.rb | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 502b6d6..0daa537 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -7,7 +7,7 @@ module GitHubChangelogGenerator class Parser # parse options with optparse def self.parse_options - options = get_default_options + options = default_options ParserFile.new(options).parse! @@ -159,8 +159,8 @@ module GitHubChangelogGenerator end # just get default options - def self.get_default_options - options = { + def self.default_options + { tag1: nil, tag2: nil, date_format: "%Y-%m-%d", @@ -188,8 +188,6 @@ module GitHubChangelogGenerator enhancement_prefix: "**Implemented enhancements:**", git_remote: "origin" } - - options end def self.user_and_project_from_git diff --git a/lib/github_changelog_generator/task.rb b/lib/github_changelog_generator/task.rb index 8903833..e87f7f2 100644 --- a/lib/github_changelog_generator/task.rb +++ b/lib/github_changelog_generator/task.rb @@ -43,11 +43,9 @@ module GitHubChangelogGenerator task @name do # mimick parse_options - options = Parser.get_default_options + options = Parser.default_options - if options[:user].nil? || options[:project].nil? - Parser.detect_user_and_project(options) - end + Parser.user_and_project_from_git(options) OPTIONS.each do |o| v = instance_variable_get("@#{o}") diff --git a/spec/unit/parse_file_spec.rb b/spec/unit/parse_file_spec.rb index eb8af0c..8c00f83 100644 --- a/spec/unit/parse_file_spec.rb +++ b/spec/unit/parse_file_spec.rb @@ -24,7 +24,7 @@ describe GitHubChangelogGenerator::ParserFile do end context "when override default values" do - let(:default_options) { GitHubChangelogGenerator::Parser.get_default_options } + let(:default_options) { GitHubChangelogGenerator::Parser.default_options } let(:options) { { params_file: "spec/files/github_changelog_params_override" }.merge(default_options) } let(:options_before_change) { options.dup } let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }