refactoring

This commit is contained in:
Petr Korolev 2015-03-05 10:33:54 +02:00
parent 4dc5a094d2
commit 6159ebba2f
2 changed files with 11 additions and 21 deletions

View File

@ -20,13 +20,7 @@ module GitHubChangelogGenerator
@options = Parser.parse_options @options = Parser.parse_options
if options[:verbose] fetch_github_token
puts 'Input options:'
pp options
puts ''
end
github_token
github_options = {per_page: PER_PAGE_NUMBER} github_options = {per_page: PER_PAGE_NUMBER}
github_options[:oauth_token] = @github_token unless @github_token.nil? github_options[:oauth_token] = @github_token unless @github_token.nil?
@ -113,11 +107,6 @@ module GitHubChangelogGenerator
puts JSON.pretty_generate(json) puts JSON.pretty_generate(json)
end end
def exec_command(cmd)
exec_cmd = "cd #{$project_path} and #{cmd}"
%x[#{exec_cmd}]
end
def fetch_merged_at_pull_requests def fetch_merged_at_pull_requests
if @options[:verbose] if @options[:verbose]
print "Fetching merged dates...\r" print "Fetching merged dates...\r"
@ -314,12 +303,8 @@ module GitHubChangelogGenerator
tags tags
end end
def github_token def fetch_github_token
if @options[:token] env_var = @options[:token] ? @options[:token] : (ENV.fetch 'CHANGELOG_GITHUB_TOKEN', nil)
return @github_token ||= @options[:token]
end
env_var = ENV.fetch 'CHANGELOG_GITHUB_TOKEN', nil
unless env_var unless env_var
puts "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found.".yellow puts "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found.".yellow

View File

@ -6,8 +6,8 @@ require_relative 'version'
module GitHubChangelogGenerator module GitHubChangelogGenerator
class Parser class Parser
def self.parse_options def self.parse_options
# :include_labels => %w(bug enhancement),
hash = { options = {
:tag1 => nil, :tag1 => nil,
:tag2 => nil, :tag2 => nil,
:format => '%Y-%m-%d', :format => '%Y-%m-%d',
@ -28,7 +28,6 @@ module GitHubChangelogGenerator
:unreleased => true, :unreleased => true,
:unreleased_label => 'Unreleased' :unreleased_label => 'Unreleased'
} }
options = hash
parser = OptionParser.new { |opts| parser = OptionParser.new { |opts|
opts.banner = 'Usage: github_changelog_generator [options]' opts.banner = 'Usage: github_changelog_generator [options]'
@ -149,6 +148,12 @@ module GitHubChangelogGenerator
options[:tag2] = ARGV[1] options[:tag2] = ARGV[1]
end end
if options[:verbose]
puts 'Performing task with options:'
pp options
puts ''
end
options options
end end
end end