Style: Use attr_reader for options
- prefer parentheses
This commit is contained in:
parent
fe0fd94ea3
commit
1c8a2d29ea
|
@ -18,18 +18,18 @@ module GitHubChangelogGenerator
|
||||||
# Example:
|
# Example:
|
||||||
# generator = GitHubChangelogGenerator::Generator.new
|
# generator = GitHubChangelogGenerator::Generator.new
|
||||||
# content = generator.compound_changelog
|
# content = generator.compound_changelog
|
||||||
def initialize(options = nil)
|
def initialize(options = {})
|
||||||
@options = options || {}
|
@options = options
|
||||||
@tag_times_hash = {}
|
@tag_times_hash = {}
|
||||||
@fetcher = GitHubChangelogGenerator::OctoFetcher.new @options
|
@fetcher = GitHubChangelogGenerator::OctoFetcher.new(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_issues_and_pr
|
def fetch_issues_and_pr
|
||||||
issues, pull_requests = @fetcher.fetch_closed_issues_and_pr
|
issues, pull_requests = @fetcher.fetch_closed_issues_and_pr
|
||||||
|
|
||||||
@pull_requests = @options[:pulls] ? get_filtered_pull_requests(pull_requests) : []
|
@pull_requests = options[:pulls] ? get_filtered_pull_requests(pull_requests) : []
|
||||||
|
|
||||||
@issues = @options[:issues] ? get_filtered_issues(issues) : []
|
@issues = options[:issues] ? get_filtered_issues(issues) : []
|
||||||
|
|
||||||
fetch_events_for_issues_and_pr
|
fetch_events_for_issues_and_pr
|
||||||
detect_actual_closed_dates(@issues + @pull_requests)
|
detect_actual_closed_dates(@issues + @pull_requests)
|
||||||
|
@ -61,18 +61,18 @@ module GitHubChangelogGenerator
|
||||||
newer_tag_link, newer_tag_name, newer_tag_time = detect_link_tag_time(newer_tag)
|
newer_tag_link, newer_tag_name, newer_tag_time = detect_link_tag_time(newer_tag)
|
||||||
|
|
||||||
github_site = options[:github_site] || "https://github.com"
|
github_site = options[:github_site] || "https://github.com"
|
||||||
project_url = "#{github_site}/#{@options[:user]}/#{@options[:project]}"
|
project_url = "#{github_site}/#{options[:user]}/#{options[:project]}"
|
||||||
|
|
||||||
log = generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)
|
log = generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)
|
||||||
|
|
||||||
if @options[:issues]
|
if options[:issues]
|
||||||
# Generate issues:
|
# Generate issues:
|
||||||
log += issues_to_log(issues, pull_requests)
|
log += issues_to_log(issues, pull_requests)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @options[:pulls]
|
if options[:pulls]
|
||||||
# Generate pull requests:
|
# Generate pull requests:
|
||||||
log += generate_sub_section(pull_requests, @options[:merge_prefix])
|
log += generate_sub_section(pull_requests, options[:merge_prefix])
|
||||||
end
|
end
|
||||||
|
|
||||||
log
|
log
|
||||||
|
@ -87,9 +87,9 @@ module GitHubChangelogGenerator
|
||||||
log = ""
|
log = ""
|
||||||
bugs_a, enhancement_a, issues_a = parse_by_sections(issues, pull_requests)
|
bugs_a, enhancement_a, issues_a = parse_by_sections(issues, pull_requests)
|
||||||
|
|
||||||
log += generate_sub_section(enhancement_a, @options[:enhancement_prefix])
|
log += generate_sub_section(enhancement_a, options[:enhancement_prefix])
|
||||||
log += generate_sub_section(bugs_a, @options[:bug_prefix])
|
log += generate_sub_section(bugs_a, options[:bug_prefix])
|
||||||
log += generate_sub_section(issues_a, @options[:issue_prefix])
|
log += generate_sub_section(issues_a, options[:issue_prefix])
|
||||||
log
|
log
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -107,31 +107,31 @@ module GitHubChangelogGenerator
|
||||||
issues.each do |dict|
|
issues.each do |dict|
|
||||||
added = false
|
added = false
|
||||||
dict["labels"].each do |label|
|
dict["labels"].each do |label|
|
||||||
if @options[:bug_labels].include? label["name"]
|
if options[:bug_labels].include?(label["name"])
|
||||||
bugs_a.push dict
|
bugs_a.push(dict)
|
||||||
added = true
|
added = true
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
if @options[:enhancement_labels].include? label["name"]
|
if options[:enhancement_labels].include?(label["name"])
|
||||||
enhancement_a.push dict
|
enhancement_a.push(dict)
|
||||||
added = true
|
added = true
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
issues_a.push dict unless added
|
issues_a.push(dict) unless added
|
||||||
end
|
end
|
||||||
|
|
||||||
added_pull_requests = []
|
added_pull_requests = []
|
||||||
pull_requests.each do |pr|
|
pull_requests.each do |pr|
|
||||||
pr["labels"].each do |label|
|
pr["labels"].each do |label|
|
||||||
if @options[:bug_labels].include? label["name"]
|
if options[:bug_labels].include?(label["name"])
|
||||||
bugs_a.push pr
|
bugs_a.push(pr)
|
||||||
added_pull_requests.push pr
|
added_pull_requests.push(pr)
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
if @options[:enhancement_labels].include? label["name"]
|
if options[:enhancement_labels].include?(label["name"])
|
||||||
enhancement_a.push pr
|
enhancement_a.push(pr)
|
||||||
added_pull_requests.push pr
|
added_pull_requests.push(pr)
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ module GitHubChangelogGenerator
|
||||||
# Fetch event for issues and pull requests
|
# Fetch event for issues and pull requests
|
||||||
# @return [Array] array of fetched issues
|
# @return [Array] array of fetched issues
|
||||||
def fetch_events_for_issues_and_pr
|
def fetch_events_for_issues_and_pr
|
||||||
if @options[:verbose]
|
if options[:verbose]
|
||||||
print "Fetching events for issues and PR: 0/#{@issues.count + @pull_requests.count}\r"
|
print "Fetching events for issues and PR: 0/#{@issues.count + @pull_requests.count}\r"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
# Async fetching of all tags dates
|
# Async fetching of all tags dates
|
||||||
def fetch_tags_dates(tags)
|
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
|
||||||
|
@ -25,17 +25,17 @@ module GitHubChangelogGenerator
|
||||||
print " \r"
|
print " \r"
|
||||||
threads << Thread.new do
|
threads << Thread.new do
|
||||||
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
|
||||||
end
|
end
|
||||||
threads.each(&:join)
|
threads.each(&:join)
|
||||||
puts "Fetching tags dates: #{i}" if @options[:verbose]
|
puts "Fetching tags dates: #{i}" if options[:verbose]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find correct closed dates, if issues was closed by commits
|
# Find correct closed dates, if issues was closed by commits
|
||||||
def detect_actual_closed_dates(issues)
|
def detect_actual_closed_dates(issues)
|
||||||
print "Fetching closed dates for issues...\r" if @options[:verbose]
|
print "Fetching closed dates for issues...\r" if options[:verbose]
|
||||||
|
|
||||||
issues.each_slice(MAX_THREAD_NUMBER) do |issues_slice|
|
issues.each_slice(MAX_THREAD_NUMBER) do |issues_slice|
|
||||||
threads = []
|
threads = []
|
||||||
|
@ -44,7 +44,7 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
threads.each(&:join)
|
threads.each(&:join)
|
||||||
end
|
end
|
||||||
puts "Fetching closed dates for issues: Done!" if @options[:verbose]
|
puts "Fetching closed dates for issues: Done!" if options[:verbose]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fill :actual_date parameter of specified issue by closed date of the commit, if it was closed by commit.
|
# Fill :actual_date parameter of specified issue by closed date of the commit, if it was closed by commit.
|
||||||
|
|
|
@ -9,44 +9,21 @@ module GitHubChangelogGenerator
|
||||||
fetch_issues_and_pr
|
fetch_issues_and_pr
|
||||||
|
|
||||||
log = ""
|
log = ""
|
||||||
log += @options[:frontmatter] if @options[:frontmatter]
|
log += options[:frontmatter] if options[:frontmatter]
|
||||||
log += "#{@options[:header]}\n\n"
|
log += "#{options[:header]}\n\n"
|
||||||
|
|
||||||
log += if @options[:unreleased_only]
|
log += if options[:unreleased_only]
|
||||||
generate_log_between_tags(filtered_tags[0], nil)
|
generate_log_between_tags(filtered_tags[0], nil)
|
||||||
else
|
else
|
||||||
generate_log_for_all_tags
|
generate_log_for_all_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
log += File.read(@options[:base]) if File.file?(@options[:base])
|
log += File.read(options[:base]) if File.file?(options[:base])
|
||||||
|
|
||||||
log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
|
log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
|
||||||
@log = log
|
@log = log
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [String] temp method should be removed soon
|
|
||||||
def generate_for_2_tags(log)
|
|
||||||
tag1 = @options[:tag1]
|
|
||||||
tag2 = @options[:tag2]
|
|
||||||
tags_strings = []
|
|
||||||
filtered_tags.each { |x| tags_strings.push(x["name"]) }
|
|
||||||
|
|
||||||
if tags_strings.include?(tag1)
|
|
||||||
if tags_strings.include?(tag2)
|
|
||||||
to_a = tags_strings.map.with_index.to_a
|
|
||||||
hash = Hash[to_a]
|
|
||||||
index1 = hash[tag1]
|
|
||||||
index2 = hash[tag2]
|
|
||||||
log += generate_log_between_tags(all_tags[index1], all_tags[index2])
|
|
||||||
else
|
|
||||||
raise ChangelogGeneratorError, "Can't find tag #{tag2} -> exit"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
raise ChangelogGeneratorError, "Can't find tag #{tag1} -> exit"
|
|
||||||
end
|
|
||||||
log
|
|
||||||
end
|
|
||||||
|
|
||||||
# @param [Array] issues List of issues on sub-section
|
# @param [Array] issues List of issues on sub-section
|
||||||
# @param [String] prefix Nae of sub-section
|
# @param [String] prefix Nae of sub-section
|
||||||
# @return [String] Generate ready-to-go sub-section
|
# @return [String] Generate ready-to-go sub-section
|
||||||
|
@ -76,21 +53,21 @@ module GitHubChangelogGenerator
|
||||||
log = ""
|
log = ""
|
||||||
|
|
||||||
# Generate date string:
|
# Generate date string:
|
||||||
time_string = newer_tag_time.strftime @options[:date_format]
|
time_string = newer_tag_time.strftime(options[:date_format])
|
||||||
|
|
||||||
# Generate tag name and link
|
# Generate tag name and link
|
||||||
release_url = if @options[:release_url]
|
release_url = if options[:release_url]
|
||||||
format(@options[:release_url], newer_tag_link)
|
format(options[:release_url], newer_tag_link)
|
||||||
else
|
else
|
||||||
"#{project_url}/tree/#{newer_tag_link}"
|
"#{project_url}/tree/#{newer_tag_link}"
|
||||||
end
|
end
|
||||||
log += if newer_tag_name.equal? @options[:unreleased_label]
|
log += if newer_tag_name.equal?(options[:unreleased_label])
|
||||||
"## [#{newer_tag_name}](#{release_url})\n\n"
|
"## [#{newer_tag_name}](#{release_url})\n\n"
|
||||||
else
|
else
|
||||||
"## [#{newer_tag_name}](#{release_url}) (#{time_string})\n"
|
"## [#{newer_tag_name}](#{release_url}) (#{time_string})\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
if @options[:compare_link] && older_tag_link
|
if options[:compare_link] && older_tag_link
|
||||||
# Generate compare link
|
# Generate compare link
|
||||||
log += "[Full Changelog](#{project_url}/compare/#{older_tag_link}...#{newer_tag_link})\n\n"
|
log += "[Full Changelog](#{project_url}/compare/#{older_tag_link}...#{newer_tag_link})\n\n"
|
||||||
end
|
end
|
||||||
|
@ -123,7 +100,7 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
newer_tag_name = newer_tag.nil? ? nil : newer_tag["name"]
|
newer_tag_name = newer_tag.nil? ? nil : newer_tag["name"]
|
||||||
|
|
||||||
if @options[:filter_issues_by_milestone]
|
if options[:filter_issues_by_milestone]
|
||||||
# delete excess irrelevant issues (according milestones). Issue #22.
|
# delete excess irrelevant issues (according milestones). Issue #22.
|
||||||
filtered_issues = filter_by_milestone(filtered_issues, newer_tag_name, @issues)
|
filtered_issues = filter_by_milestone(filtered_issues, newer_tag_name, @issues)
|
||||||
filtered_pull_requests = filter_by_milestone(filtered_pull_requests, newer_tag_name, @pull_requests)
|
filtered_pull_requests = filter_by_milestone(filtered_pull_requests, newer_tag_name, @pull_requests)
|
||||||
|
@ -134,7 +111,7 @@ module GitHubChangelogGenerator
|
||||||
# The full cycle of generation for whole project
|
# The full cycle of generation for whole project
|
||||||
# @return [String] The complete change log
|
# @return [String] The complete change log
|
||||||
def generate_log_for_all_tags
|
def generate_log_for_all_tags
|
||||||
puts "Generating log..." if @options[:verbose]
|
puts "Generating log..." if options[:verbose]
|
||||||
|
|
||||||
log = generate_unreleased_section
|
log = generate_unreleased_section
|
||||||
|
|
||||||
|
@ -148,7 +125,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(filtered_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
|
||||||
|
@ -172,12 +149,12 @@ module GitHubChangelogGenerator
|
||||||
private
|
private
|
||||||
|
|
||||||
def issue_line_with_user(line, issue)
|
def issue_line_with_user(line, issue)
|
||||||
return line if !@options[:author] || issue.pull_request.nil?
|
return line if !options[:author] || issue.pull_request.nil?
|
||||||
|
|
||||||
user = issue["user"]
|
user = issue["user"]
|
||||||
return "#{line} ({Null user})" unless user
|
return "#{line} ({Null user})" unless user
|
||||||
|
|
||||||
if @options[:usernames_as_github_logins]
|
if options[:usernames_as_github_logins]
|
||||||
"#{line} (@#{user['login']})"
|
"#{line} (@#{user['login']})"
|
||||||
else
|
else
|
||||||
"#{line} ([#{user['login']}](#{user['html_url']}))"
|
"#{line} ([#{user['login']}](#{user['html_url']}))"
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
class Generator
|
class Generator
|
||||||
# delete all labels with labels from @options[:exclude_labels] array
|
# delete all labels with labels from options[:exclude_labels] array
|
||||||
# @param [Array] issues
|
# @param [Array] issues
|
||||||
# @return [Array] filtered array
|
# @return [Array] filtered array
|
||||||
def exclude_issues_by_labels(issues)
|
def exclude_issues_by_labels(issues)
|
||||||
return issues if !@options[:exclude_labels] || @options[:exclude_labels].empty?
|
return issues if !options[:exclude_labels] || options[:exclude_labels].empty?
|
||||||
|
|
||||||
issues.reject do |issue|
|
issues.reject do |issue|
|
||||||
labels = issue["labels"].map { |l| l["name"] }
|
labels = issue["labels"].map { |l| l["name"] }
|
||||||
(labels & @options[:exclude_labels]).any?
|
(labels & options[:exclude_labels]).any?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
# @return [Array] issues without labels or empty array if add_issues_wo_labels is false
|
# @return [Array] issues without labels or empty array if add_issues_wo_labels is false
|
||||||
def filter_wo_labels(issues)
|
def filter_wo_labels(issues)
|
||||||
if @options[:add_issues_wo_labels]
|
if options[:add_issues_wo_labels]
|
||||||
issues_wo_labels = issues.select do |issue|
|
issues_wo_labels = issues.select do |issue|
|
||||||
!issue["labels"].map { |l| l["name"] }.any?
|
!issue["labels"].map { |l| l["name"] }.any?
|
||||||
end
|
end
|
||||||
|
@ -131,11 +131,11 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_by_include_labels(issues)
|
def filter_by_include_labels(issues)
|
||||||
if @options[:include_labels].nil?
|
if options[:include_labels].nil?
|
||||||
issues
|
issues
|
||||||
else
|
else
|
||||||
issues.select do |issue|
|
issues.select do |issue|
|
||||||
labels = issue["labels"].map { |l| l["name"] } & @options[:include_labels]
|
labels = issue["labels"].map { |l| l["name"] } & options[:include_labels]
|
||||||
labels.any?
|
labels.any?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -154,18 +154,18 @@ module GitHubChangelogGenerator
|
||||||
# @return [Array] Filtered issues
|
# @return [Array] Filtered issues
|
||||||
def get_filtered_issues(issues)
|
def get_filtered_issues(issues)
|
||||||
issues = filter_array_by_labels(issues)
|
issues = filter_array_by_labels(issues)
|
||||||
puts "Filtered issues: #{issues.count}" if @options[:verbose]
|
puts "Filtered issues: #{issues.count}" if options[:verbose]
|
||||||
issues
|
issues
|
||||||
end
|
end
|
||||||
|
|
||||||
# This method fetches missing params for PR and filter them by specified options
|
# This method fetches missing params for PR and filter them by specified options
|
||||||
# It include add all PR's with labels from @options[:include_labels] array
|
# It include add all PR's with labels from options[:include_labels] array
|
||||||
# And exclude all from :exclude_labels array.
|
# And exclude all from :exclude_labels array.
|
||||||
# @return [Array] filtered PR's
|
# @return [Array] filtered PR's
|
||||||
def get_filtered_pull_requests(pull_requests)
|
def get_filtered_pull_requests(pull_requests)
|
||||||
pull_requests = filter_array_by_labels(pull_requests)
|
pull_requests = filter_array_by_labels(pull_requests)
|
||||||
pull_requests = filter_merged_pull_requests(pull_requests)
|
pull_requests = filter_merged_pull_requests(pull_requests)
|
||||||
puts "Filtered pull requests: #{pull_requests.count}" if @options[:verbose]
|
puts "Filtered pull requests: #{pull_requests.count}" if options[:verbose]
|
||||||
pull_requests
|
pull_requests
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ module GitHubChangelogGenerator
|
||||||
# :merged_at - is a date, when issue PR was merged.
|
# :merged_at - is a date, when issue PR was merged.
|
||||||
# More correct to use merged date, rather than closed date.
|
# More correct to use merged date, rather than closed date.
|
||||||
def filter_merged_pull_requests(pull_requests)
|
def filter_merged_pull_requests(pull_requests)
|
||||||
print "Fetching merged dates...\r" if @options[:verbose]
|
print "Fetching merged dates...\r" if options[:verbose]
|
||||||
closed_pull_requests = @fetcher.fetch_closed_pull_requests
|
closed_pull_requests = @fetcher.fetch_closed_pull_requests
|
||||||
|
|
||||||
pull_requests.each do |pr|
|
pull_requests.each do |pr|
|
||||||
|
|
|
@ -34,7 +34,7 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
# Sort all tags by date, newest to oldest
|
# 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|
|
||||||
get_time_of_tag(x)
|
get_time_of_tag(x)
|
||||||
end.reverse!
|
end.reverse!
|
||||||
|
@ -68,12 +68,12 @@ module GitHubChangelogGenerator
|
||||||
newer_tag_time = newer_tag.nil? ? Time.new : 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]
|
||||||
newer_tag_name = @options[:future_release]
|
newer_tag_name = options[:future_release]
|
||||||
newer_tag_link = @options[:future_release]
|
newer_tag_link = options[:future_release]
|
||||||
else
|
else
|
||||||
# put unreleased label if there is no name for the tag
|
# put unreleased label if there is no name for the tag
|
||||||
newer_tag_name = newer_tag.nil? ? @options[:unreleased_label] : newer_tag["name"]
|
newer_tag_name = newer_tag.nil? ? options[:unreleased_label] : newer_tag["name"]
|
||||||
newer_tag_link = newer_tag.nil? ? "HEAD" : newer_tag_name
|
newer_tag_link = newer_tag.nil? ? "HEAD" : newer_tag_name
|
||||||
end
|
end
|
||||||
[newer_tag_link, newer_tag_name, newer_tag_time]
|
[newer_tag_link, newer_tag_name, newer_tag_time]
|
||||||
|
@ -81,17 +81,17 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
# @return [Object] try to find newest tag using #Reader and :base option if specified otherwise returns nil
|
# @return [Object] try to find newest tag using #Reader and :base option if specified otherwise returns nil
|
||||||
def detect_since_tag
|
def detect_since_tag
|
||||||
@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
|
def detect_due_tag
|
||||||
@due_tag ||= @options.fetch(:due_tag, nil)
|
@due_tag ||= options.fetch(:due_tag, nil)
|
||||||
end
|
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)
|
||||||
|
|
||||||
sections = GitHubChangelogGenerator::Reader.new.read(@options[:base])
|
sections = GitHubChangelogGenerator::Reader.new.read(options[:base])
|
||||||
sections.first["version"] if sections && sections.any?
|
sections.first["version"] if sections && sections.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -150,13 +150,13 @@ module GitHubChangelogGenerator
|
||||||
filtered_tags = all_tags
|
filtered_tags = all_tags
|
||||||
tag_names = filtered_tags.map { |ft| ft["name"] }
|
tag_names = filtered_tags.map { |ft| ft["name"] }
|
||||||
|
|
||||||
if @options[:between_tags]
|
if options[:between_tags]
|
||||||
@options[:between_tags].each do |tag|
|
options[:between_tags].each do |tag|
|
||||||
unless tag_names.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
|
||||||
filtered_tags = all_tags.select { |tag| @options[:between_tags].include? tag["name"] }
|
filtered_tags = all_tags.select { |tag| options[:between_tags].include?(tag["name"]) }
|
||||||
end
|
end
|
||||||
filtered_tags
|
filtered_tags
|
||||||
end
|
end
|
||||||
|
@ -164,9 +164,9 @@ module GitHubChangelogGenerator
|
||||||
# @param [Array] all_tags all tags
|
# @param [Array] all_tags all tags
|
||||||
# @return [Array] filtered tags according :exclude_tags or :exclude_tags_regex option
|
# @return [Array] filtered tags according :exclude_tags or :exclude_tags_regex option
|
||||||
def filter_excluded_tags(all_tags)
|
def filter_excluded_tags(all_tags)
|
||||||
if @options[:exclude_tags]
|
if options[:exclude_tags]
|
||||||
apply_exclude_tags(all_tags)
|
apply_exclude_tags(all_tags)
|
||||||
elsif @options[:exclude_tags_regex]
|
elsif options[:exclude_tags_regex]
|
||||||
apply_exclude_tags_regex(all_tags)
|
apply_exclude_tags_regex(all_tags)
|
||||||
else
|
else
|
||||||
all_tags
|
all_tags
|
||||||
|
@ -176,15 +176,15 @@ module GitHubChangelogGenerator
|
||||||
private
|
private
|
||||||
|
|
||||||
def apply_exclude_tags(all_tags)
|
def apply_exclude_tags(all_tags)
|
||||||
if @options[:exclude_tags].is_a?(Regexp)
|
if options[:exclude_tags].is_a?(Regexp)
|
||||||
filter_tags_with_regex(all_tags, @options[:exclude_tags])
|
filter_tags_with_regex(all_tags, options[:exclude_tags])
|
||||||
else
|
else
|
||||||
filter_exact_tags(all_tags)
|
filter_exact_tags(all_tags)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_exclude_tags_regex(all_tags)
|
def apply_exclude_tags_regex(all_tags)
|
||||||
filter_tags_with_regex(all_tags, Regexp.new(@options[:exclude_tags_regex]))
|
filter_tags_with_regex(all_tags, Regexp.new(options[:exclude_tags_regex]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_tags_with_regex(all_tags, regex)
|
def filter_tags_with_regex(all_tags, regex)
|
||||||
|
@ -193,16 +193,16 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_exact_tags(all_tags)
|
def filter_exact_tags(all_tags)
|
||||||
@options[:exclude_tags].each do |tag|
|
options[:exclude_tags].each do |tag|
|
||||||
warn_if_tag_not_found(all_tags, tag)
|
warn_if_tag_not_found(all_tags, tag)
|
||||||
end
|
end
|
||||||
all_tags.reject { |tag| @options[:exclude_tags].include? tag["name"] }
|
all_tags.reject { |tag| options[:exclude_tags].include?(tag["name"]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def warn_if_nonmatching_regex(all_tags)
|
def warn_if_nonmatching_regex(all_tags)
|
||||||
unless all_tags.map { |t| t["name"] }.any? { |t| @options[:exclude_tags] =~ t }
|
unless all_tags.map { |t| t["name"] }.any? { |t| options[:exclude_tags] =~ t }
|
||||||
Helper.log.warn "Warning: unable to reject any tag, using regex "\
|
Helper.log.warn "Warning: unable to reject any tag, using regex "\
|
||||||
"#{@options[:exclude_tags].inspect} in --exclude-tags "\
|
"#{options[:exclude_tags].inspect} in --exclude-tags "\
|
||||||
"option."
|
"option."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user