refactoring
This commit is contained in:
parent
a415010e86
commit
8906fe5022
|
@ -18,7 +18,6 @@ module GitHubChangelogGenerator
|
||||||
@user = @options[:user]
|
@user = @options[:user]
|
||||||
@project = @options[:project]
|
@project = @options[:project]
|
||||||
@github_token = fetch_github_token
|
@github_token = fetch_github_token
|
||||||
@tag_times_hash = {}
|
|
||||||
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?
|
||||||
github_options[:endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].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}"
|
Helper.log.info "Fetching events for issues and PR: #{i}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Try to find tag date in local hash.
|
# Fetch tag time from repo
|
||||||
# Otherwise fFetch tag time and put it to local hash file.
|
#
|
||||||
# @param [String] tag_name name of the tag
|
# @param [Hash] tag
|
||||||
# @return [Time] time of specified tag
|
# @return [Time] time of specified tag
|
||||||
def get_time_of_tag(tag_name)
|
def fetch_date_of_tag(tag)
|
||||||
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
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
github_git_data_commits_get = @github.git_data.commits.get @options[:user],
|
commit_data = @github.git_data.commits.get @options[:user],
|
||||||
@options[:project],
|
@options[:project],
|
||||||
tag_name["commit"]["sha"]
|
tag["commit"]["sha"]
|
||||||
rescue
|
rescue
|
||||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
||||||
end
|
end
|
||||||
time_string = github_git_data_commits_get["committer"]["date"]
|
time_string = commit_data["committer"]["date"]
|
||||||
@tag_times_hash[tag_name["name"]] = Time.parse(time_string)
|
Time.parse(time_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fetch commit for specified event
|
# Fetch commit for specified event
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require "github_changelog_generator/fetcher"
|
require_relative "../fetcher"
|
||||||
require_relative "generator_generation"
|
require_relative "generator_generation"
|
||||||
require_relative "generator_fetcher"
|
require_relative "generator_fetcher"
|
||||||
require_relative "generator_processor"
|
require_relative "generator_processor"
|
||||||
|
@ -19,7 +19,7 @@ module GitHubChangelogGenerator
|
||||||
# content = generator.compound_changelog
|
# content = generator.compound_changelog
|
||||||
def initialize(options = nil)
|
def initialize(options = nil)
|
||||||
@options = options || {}
|
@options = options || {}
|
||||||
|
@tag_times_hash = {}
|
||||||
@fetcher = GitHubChangelogGenerator::Fetcher.new @options
|
@fetcher = GitHubChangelogGenerator::Fetcher.new @options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ module GitHubChangelogGenerator
|
||||||
@filtered_tags.each do |tag|
|
@filtered_tags.each do |tag|
|
||||||
print " \r"
|
print " \r"
|
||||||
threads << Thread.new do
|
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]
|
print "Fetching tags dates: #{i + 1}/#{all}\r" if @options[:verbose]
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ module GitHubChangelogGenerator
|
||||||
tag1 = @options[:tag1]
|
tag1 = @options[:tag1]
|
||||||
tag2 = @options[:tag2]
|
tag2 = @options[:tag2]
|
||||||
tags_strings = []
|
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?(tag1)
|
||||||
if tags_strings.include?(tag2)
|
if tags_strings.include?(tag2)
|
||||||
|
@ -128,11 +128,11 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
log = generate_unreleased_section
|
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])
|
log += generate_log_between_tags(all_tags[index], all_tags[index - 1])
|
||||||
end
|
end
|
||||||
if @filtered_tags.count != 0
|
if @filtered_tags.count != 0
|
||||||
log += generate_log_between_tags(nil, all_tags.last)
|
log += generate_log_between_tags(nil, filtered_tags.last)
|
||||||
end
|
end
|
||||||
|
|
||||||
log
|
log
|
||||||
|
@ -141,7 +141,7 @@ module GitHubChangelogGenerator
|
||||||
def generate_unreleased_section
|
def generate_unreleased_section
|
||||||
log = ""
|
log = ""
|
||||||
if @options[:unreleased]
|
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
|
log += unreleased_log if unreleased_log
|
||||||
end
|
end
|
||||||
log
|
log
|
||||||
|
|
|
@ -72,8 +72,8 @@ module GitHubChangelogGenerator
|
||||||
# in case if not tags specified - return unchanged array
|
# in case if not tags specified - return unchanged array
|
||||||
return array if older_tag.nil? && newer_tag.nil?
|
return array if older_tag.nil? && newer_tag.nil?
|
||||||
|
|
||||||
newer_tag_time = newer_tag && @fetcher.get_time_of_tag(newer_tag)
|
newer_tag_time = newer_tag && get_time_of_tag(newer_tag)
|
||||||
older_tag_time = older_tag && @fetcher.get_time_of_tag(older_tag)
|
older_tag_time = older_tag && get_time_of_tag(older_tag)
|
||||||
|
|
||||||
array.select do |req|
|
array.select do |req|
|
||||||
if req[hash_key]
|
if req[hash_key]
|
||||||
|
|
|
@ -10,7 +10,25 @@ module GitHubChangelogGenerator
|
||||||
# Sort all tags by date
|
# Sort all tags by date
|
||||||
def sort_tags_by_date(tags)
|
def sort_tags_by_date(tags)
|
||||||
puts "Sorting tags..." if @options[:verbose]
|
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
|
end
|
||||||
|
|
||||||
# Detect link, name and time for specified tag.
|
# Detect link, name and time for specified tag.
|
||||||
|
@ -19,7 +37,7 @@ module GitHubChangelogGenerator
|
||||||
# @return [Array] link, name and time of the tag
|
# @return [Array] link, name and time of the tag
|
||||||
def detect_link_tag_time(newer_tag)
|
def detect_link_tag_time(newer_tag)
|
||||||
# if tag is nil - set current time
|
# 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 it's future release tag - set this value
|
||||||
if newer_tag.nil? && @options[:future_release]
|
if newer_tag.nil? && @options[:future_release]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user