refactoring

This commit is contained in:
Petr Korolev
2015-06-10 16:49:06 +03:00
parent a415010e86
commit 8906fe5022
6 changed files with 38 additions and 27 deletions
@@ -1,4 +1,4 @@
require "github_changelog_generator/fetcher"
require_relative "../fetcher"
require_relative "generator_generation"
require_relative "generator_fetcher"
require_relative "generator_processor"
@@ -19,7 +19,7 @@ module GitHubChangelogGenerator
# content = generator.compound_changelog
def initialize(options = nil)
@options = options || {}
@tag_times_hash = {}
@fetcher = GitHubChangelogGenerator::Fetcher.new @options
end
@@ -21,7 +21,7 @@ module GitHubChangelogGenerator
@filtered_tags.each do |tag|
print " \r"
threads << Thread.new do
@fetcher.get_time_of_tag(tag)
get_time_of_tag(tag)
print "Fetching tags dates: #{i + 1}/#{all}\r" if @options[:verbose]
i += 1
end
@@ -24,7 +24,7 @@ module GitHubChangelogGenerator
tag1 = @options[:tag1]
tag2 = @options[:tag2]
tags_strings = []
all_tags.each { |x| tags_strings.push(x["name"]) }
filtered_tags.each { |x| tags_strings.push(x["name"]) }
if tags_strings.include?(tag1)
if tags_strings.include?(tag2)
@@ -128,11 +128,11 @@ module GitHubChangelogGenerator
log = generate_unreleased_section
(1...all_tags.size).each do |index|
(1...filtered_tags.size).each do |index|
log += generate_log_between_tags(all_tags[index], all_tags[index - 1])
end
if @filtered_tags.count != 0
log += generate_log_between_tags(nil, all_tags.last)
log += generate_log_between_tags(nil, filtered_tags.last)
end
log
@@ -141,7 +141,7 @@ module GitHubChangelogGenerator
def generate_unreleased_section
log = ""
if @options[:unreleased]
unreleased_log = generate_log_between_tags(all_tags[0], nil)
unreleased_log = generate_log_between_tags(filtered_tags[0], nil)
log += unreleased_log if unreleased_log
end
log
@@ -72,8 +72,8 @@ module GitHubChangelogGenerator
# in case if not tags specified - return unchanged array
return array if older_tag.nil? && newer_tag.nil?
newer_tag_time = newer_tag && @fetcher.get_time_of_tag(newer_tag)
older_tag_time = older_tag && @fetcher.get_time_of_tag(older_tag)
newer_tag_time = newer_tag && get_time_of_tag(newer_tag)
older_tag_time = older_tag && get_time_of_tag(older_tag)
array.select do |req|
if req[hash_key]
@@ -10,7 +10,25 @@ module GitHubChangelogGenerator
# Sort all tags by date
def sort_tags_by_date(tags)
puts "Sorting tags..." if @options[:verbose]
tags.sort_by! { |x| @fetcher.get_time_of_tag(x) }.reverse!
tags.sort_by! do |x|
get_time_of_tag(x)
end.reverse!
end
# Try to find tag date in local hash.
# Otherwise fFetch tag time and put it to local hash file.
# @param [Hash] tag_name name of the tag
# @return [Time] time of specified tag
def get_time_of_tag(tag_name)
fail ChangelogGeneratorError, "tag_name is nil".red if tag_name.nil?
if @tag_times_hash[tag_name["name"]]
@tag_times_hash[tag_name["name"]]
else
time_string = @fetcher.fetch_date_of_tag tag_name
@tag_times_hash[tag_name["name"]] = time_string
time_string
end
end
# Detect link, name and time for specified tag.
@@ -19,7 +37,7 @@ module GitHubChangelogGenerator
# @return [Array] link, name and time of the tag
def detect_link_tag_time(newer_tag)
# if tag is nil - set current time
newer_tag_time = newer_tag.nil? ? Time.new : @fetcher.get_time_of_tag(newer_tag)
newer_tag_time = newer_tag.nil? ? Time.new : get_time_of_tag(newer_tag)
# if it's future release tag - set this value
if newer_tag.nil? && @options[:future_release]