merged in the tag fixes
This commit is contained in:
parent
7dcf617d61
commit
cb6286fb83
|
@ -11,7 +11,7 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
class Generator
|
class Generator
|
||||||
attr_accessor :options, :filtered_tags, :github
|
attr_accessor :options, :filtered_tags, :github, :tag_section_mapping
|
||||||
|
|
||||||
# A Generator responsible for all logic, related with change log generation from ready-to-parse issues
|
# A Generator responsible for all logic, related with change log generation from ready-to-parse issues
|
||||||
#
|
#
|
||||||
|
|
|
@ -15,13 +15,13 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
# Async fetching of all tags dates
|
# Async fetching of all tags dates
|
||||||
def fetch_tags_dates
|
def fetch_tags_dates(tags)
|
||||||
print "Fetching tag dates...\r" if @options[:verbose]
|
print "Fetching tag dates...\r" if @options[:verbose]
|
||||||
# Async fetching tags:
|
# Async fetching tags:
|
||||||
threads = []
|
threads = []
|
||||||
i = 0
|
i = 0
|
||||||
all = @filtered_tags.count
|
all = tags.count
|
||||||
@filtered_tags.each do |tag|
|
tags.each do |tag|
|
||||||
print " \r"
|
print " \r"
|
||||||
threads << Thread.new do
|
threads << Thread.new do
|
||||||
get_time_of_tag(tag)
|
get_time_of_tag(tag)
|
||||||
|
|
|
@ -6,7 +6,6 @@ module GitHubChangelogGenerator
|
||||||
# @return [String] Generated change log file
|
# @return [String] Generated change log file
|
||||||
def compound_changelog
|
def compound_changelog
|
||||||
fetch_and_filter_tags
|
fetch_and_filter_tags
|
||||||
sort_tags_by_date(@filtered_tags)
|
|
||||||
fetch_issues_and_pr
|
fetch_issues_and_pr
|
||||||
|
|
||||||
log = ""
|
log = ""
|
||||||
|
@ -139,11 +138,9 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
log = generate_unreleased_section
|
log = generate_unreleased_section
|
||||||
|
|
||||||
(1...filtered_tags.size).each do |index|
|
@tag_section_mapping.each_pair do |_tag_section, left_right_tags|
|
||||||
log += generate_log_between_tags(filtered_tags[index], filtered_tags[index - 1])
|
older_tag, newer_tag = left_right_tags
|
||||||
end
|
log += generate_log_between_tags(older_tag, newer_tag)
|
||||||
if filtered_tags.any?
|
|
||||||
log += generate_log_between_tags(nil, filtered_tags.last)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
log
|
log
|
||||||
|
|
|
@ -3,11 +3,34 @@ module GitHubChangelogGenerator
|
||||||
class Generator
|
class Generator
|
||||||
# fetch, filter tags, fetch dates and sort them in time order
|
# fetch, filter tags, fetch dates and sort them in time order
|
||||||
def fetch_and_filter_tags
|
def fetch_and_filter_tags
|
||||||
@filtered_tags = get_filtered_tags(@fetcher.get_all_tags)
|
detect_since_tag
|
||||||
fetch_tags_dates
|
detect_due_tag
|
||||||
|
|
||||||
|
all_tags = @fetcher.get_all_tags
|
||||||
|
fetch_tags_dates(all_tags) # Creates a Hash @tag_times_hash
|
||||||
|
sorted_tags = sort_tags_by_date(all_tags)
|
||||||
|
@filtered_tags = get_filtered_tags(sorted_tags)
|
||||||
|
|
||||||
|
@tag_section_mapping = build_tag_section_mapping(@filtered_tags, all_tags)
|
||||||
|
|
||||||
|
@filtered_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sort all tags by date
|
# @param [Array] filtered_tags are the tags that need a subsection output
|
||||||
|
# @param [Array] all_tags is the list of all tags ordered from newest -> oldest
|
||||||
|
# @return [Hash] key is the tag to output, value is an array of [Left Tag, Right Tag]
|
||||||
|
# PRs to include in this section will be >= [Left Tag Date] and <= [Right Tag Date]
|
||||||
|
def build_tag_section_mapping(filtered_tags, all_tags)
|
||||||
|
tag_mapping = {}
|
||||||
|
filtered_tags.each do |tag|
|
||||||
|
older_tag_idx = all_tags.index(tag) + 1
|
||||||
|
older_tag = all_tags[older_tag_idx]
|
||||||
|
tag_mapping[tag] = [older_tag, tag]
|
||||||
|
end
|
||||||
|
tag_mapping
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sort all tags by date, newest to oldest
|
||||||
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! do |x|
|
tags.sort_by! do |x|
|
||||||
|
@ -58,6 +81,10 @@ module GitHubChangelogGenerator
|
||||||
@since_tag ||= @options.fetch(:since_tag) { version_of_first_item }
|
@since_tag ||= @options.fetch(:since_tag) { version_of_first_item }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def detect_due_tag
|
||||||
|
@due_tag ||= @options.fetch(:due_tag, nil)
|
||||||
|
end
|
||||||
|
|
||||||
def version_of_first_item
|
def version_of_first_item
|
||||||
return unless File.file?(@options[:base].to_s)
|
return unless File.file?(@options[:base].to_s)
|
||||||
|
|
||||||
|
@ -70,6 +97,7 @@ module GitHubChangelogGenerator
|
||||||
# @return [Array]
|
# @return [Array]
|
||||||
def get_filtered_tags(all_tags)
|
def get_filtered_tags(all_tags)
|
||||||
filtered_tags = filter_since_tag(all_tags)
|
filtered_tags = filter_since_tag(all_tags)
|
||||||
|
filtered_tags = filter_due_tag(filtered_tags)
|
||||||
filtered_tags = filter_between_tags(filtered_tags)
|
filtered_tags = filter_between_tags(filtered_tags)
|
||||||
filter_excluded_tags(filtered_tags)
|
filter_excluded_tags(filtered_tags)
|
||||||
end
|
end
|
||||||
|
@ -98,13 +126,12 @@ module GitHubChangelogGenerator
|
||||||
# @return [Array] filtered tags according :due_tag option
|
# @return [Array] filtered tags according :due_tag option
|
||||||
def filter_due_tag(all_tags)
|
def filter_due_tag(all_tags)
|
||||||
filtered_tags = all_tags
|
filtered_tags = all_tags
|
||||||
tag = @options[:due_tag]
|
tag = detect_due_tag
|
||||||
if tag
|
if tag
|
||||||
if all_tags.any? && all_tags.map { |t| t["name"] }.include?(tag)
|
if all_tags.any? && all_tags.map { |t| t["name"] }.include?(tag)
|
||||||
idx = all_tags.index { |t| t["name"] == tag }
|
idx = all_tags.index { |t| t["name"] == tag }
|
||||||
last_index = all_tags.count - 1
|
filtered_tags = if idx > 0
|
||||||
filtered_tags = if idx > 0 && idx < last_index
|
all_tags[(idx + 1)..-1]
|
||||||
all_tags[idx + 1..last_index]
|
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
@ -119,9 +146,11 @@ module GitHubChangelogGenerator
|
||||||
# @return [Array] filtered tags according :between_tags option
|
# @return [Array] filtered tags according :between_tags option
|
||||||
def filter_between_tags(all_tags)
|
def filter_between_tags(all_tags)
|
||||||
filtered_tags = all_tags
|
filtered_tags = all_tags
|
||||||
|
tag_names = filtered_tags.map(&:name)
|
||||||
|
|
||||||
if @options[:between_tags]
|
if @options[:between_tags]
|
||||||
@options[:between_tags].each do |tag|
|
@options[:between_tags].each do |tag|
|
||||||
unless all_tags.map { |t| t["name"] }.include? tag
|
unless tag_names.include? tag
|
||||||
Helper.log.warn "Warning: can't find tag #{tag}, specified with --between-tags option."
|
Helper.log.warn "Warning: can't find tag #{tag}, specified with --between-tags option."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user