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
if options[:verbose]
puts 'Input options:'
pp options
puts ''
end
github_token
fetch_github_token
github_options = {per_page: PER_PAGE_NUMBER}
github_options[:oauth_token] = @github_token unless @github_token.nil?
@ -113,11 +107,6 @@ module GitHubChangelogGenerator
puts JSON.pretty_generate(json)
end
def exec_command(cmd)
exec_cmd = "cd #{$project_path} and #{cmd}"
%x[#{exec_cmd}]
end
def fetch_merged_at_pull_requests
if @options[:verbose]
print "Fetching merged dates...\r"
@ -314,12 +303,8 @@ module GitHubChangelogGenerator
tags
end
def github_token
if @options[:token]
return @github_token ||= @options[:token]
end
env_var = ENV.fetch 'CHANGELOG_GITHUB_TOKEN', nil
def fetch_github_token
env_var = @options[:token] ? @options[:token] : (ENV.fetch 'CHANGELOG_GITHUB_TOKEN', nil)
unless env_var
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
class Parser
def self.parse_options
# :include_labels => %w(bug enhancement),
hash = {
options = {
:tag1 => nil,
:tag2 => nil,
:format => '%Y-%m-%d',
@ -28,7 +28,6 @@ module GitHubChangelogGenerator
:unreleased => true,
:unreleased_label => 'Unreleased'
}
options = hash
parser = OptionParser.new { |opts|
opts.banner = 'Usage: github_changelog_generator [options]'
@ -149,6 +148,12 @@ module GitHubChangelogGenerator
options[:tag2] = ARGV[1]
end
if options[:verbose]
puts 'Performing task with options:'
pp options
puts ''
end
options
end
end