refactoring
This commit is contained in:
parent
a415010e86
commit
8906fe5022
|
@ -18,7 +18,6 @@ module GitHubChangelogGenerator
|
|||
@user = @options[:user]
|
||||
@project = @options[:project]
|
||||
@github_token = fetch_github_token
|
||||
@tag_times_hash = {}
|
||||
github_options = { per_page: PER_PAGE_NUMBER }
|
||||
github_options[:oauth_token] = @github_token unless @github_token.nil?
|
||||
github_options[:endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil?
|
||||
|
@ -185,26 +184,20 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
|||
Helper.log.info "Fetching events for issues and PR: #{i}"
|
||||
end
|
||||
|
||||
# Try to find tag date in local hash.
|
||||
# Otherwise fFetch tag time and put it to local hash file.
|
||||
# @param [String] tag_name name of the tag
|
||||
# Fetch tag time from repo
|
||||
#
|
||||
# @param [Hash] 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"]]
|
||||
return @tag_times_hash[tag_name["name"]]
|
||||
end
|
||||
|
||||
def fetch_date_of_tag(tag)
|
||||
begin
|
||||
github_git_data_commits_get = @github.git_data.commits.get @options[:user],
|
||||
@options[:project],
|
||||
tag_name["commit"]["sha"]
|
||||
commit_data = @github.git_data.commits.get @options[:user],
|
||||
@options[:project],
|
||||
tag["commit"]["sha"]
|
||||
rescue
|
||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
||||
end
|
||||
time_string = github_git_data_commits_get["committer"]["date"]
|
||||
@tag_times_hash[tag_name["name"]] = Time.parse(time_string)
|
||||
time_string = commit_data["committer"]["date"]
|
||||
Time.parse(time_string)
|
||||
end
|
||||
|
||||
# Fetch commit for specified event
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue
Block a user