This commit is contained in:
Petr Korolev 2015-05-25 17:16:35 +03:00
parent b06bb635ed
commit b9e7463c3e
6 changed files with 121 additions and 103 deletions

View File

@ -1,37 +1,37 @@
# This configuration was generated by `rubocop --auto-gen-config` # This configuration was generated by `rubocop --auto-gen-config`
# on 2015-05-25 12:59:32 +0300 using RuboCop version 0.31.0. # on 2015-05-25 17:16:04 +0300 using RuboCop version 0.31.0.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again. # versions of RuboCop, may require this file to be generated again.
# Offense count: 16 # Offense count: 14
Metrics/AbcSize: Metrics/AbcSize:
Max: 68 Max: 57
# Offense count: 4 # Offense count: 4
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ClassLength: Metrics/ClassLength:
Enabled: false Max: 182
# Offense count: 3 # Offense count: 1
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 9 Max: 7
# Offense count: 22 # Offense count: 22
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/MethodLength: Metrics/MethodLength:
Max: 117 Max: 84
# Offense count: 4 # Offense count: 1
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Max: 12 Max: 8
# Offense count: 2 # Offense count: 2
Style/AccessorMethodName: Style/AccessorMethodName:
Enabled: false Enabled: false
# Offense count: 6 # Offense count: 8
Style/Documentation: Style/Documentation:
Enabled: false Enabled: false

View File

@ -2,6 +2,7 @@ require "github_changelog_generator/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"
require_relative "generator_tags"
module GitHubChangelogGenerator module GitHubChangelogGenerator
# Default error for ChangelogGenerator # Default error for ChangelogGenerator
@ -21,7 +22,7 @@ module GitHubChangelogGenerator
@fetcher = GitHubChangelogGenerator::Fetcher.new @options @fetcher = GitHubChangelogGenerator::Fetcher.new @options
fetch_tags fetch_and_filter_tags
fetch_issues_and_pr fetch_issues_and_pr
end end
@ -37,20 +38,6 @@ module GitHubChangelogGenerator
detect_actual_closed_dates(@issues + @pull_requests) detect_actual_closed_dates(@issues + @pull_requests)
end end
def fetch_tags
# @all_tags = get_filtered_tags
@all_tags = @fetcher.get_all_tags
fetch_tags_dates
sort_tags_by_date
end
# Sort all tags by date
def sort_tags_by_date
puts "Sorting tags..." if @options[:verbose]
@all_tags.sort_by! { |x| @fetcher.get_time_of_tag(x) }.reverse!
end
# Encapsulate characters to make markdown look as expected. # Encapsulate characters to make markdown look as expected.
# #
# @param [String] string # @param [String] string
@ -94,26 +81,6 @@ module GitHubChangelogGenerator
log log
end end
# Detect link, name and time for specified tag.
#
# @param [Hash] newer_tag newer tag. Can be nil, if it's Unreleased section.
# @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)
# if it's future release tag - set this value
if newer_tag.nil? && @options[:future_release]
newer_tag_name = @options[:future_release]
newer_tag_link = @options[:future_release]
else
# 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_link = newer_tag.nil? ? "HEAD" : newer_tag_name
end
[newer_tag_link, newer_tag_name, newer_tag_time]
end
# Generate ready-to-paste log from list of issues. # Generate ready-to-paste log from list of issues.
# #
# @param [Array] issues # @param [Array] issues

View File

@ -8,8 +8,6 @@ module GitHubChangelogGenerator
if @options[:unreleased_only] if @options[:unreleased_only]
log += generate_log_between_tags(all_tags[0], nil) log += generate_log_between_tags(all_tags[0], nil)
elsif @options[:tag1] && @options[:tag2]
log = generate_for_2_tags(log)
else else
log += generate_log_for_all_tags log += generate_log_for_all_tags
end end

View File

@ -138,23 +138,6 @@ module GitHubChangelogGenerator
filtered_issues filtered_issues
end end
# Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags
#
# @return [Array]
def get_filtered_tags
all_tags = @fetcher.get_all_tags
filtered_tags = []
if @options[:between_tags]
@options[:between_tags].each do |tag|
unless all_tags.include? tag
puts "Warning: can't find tag #{tag}, specified with --between-tags option.".yellow
end
end
filtered_tags = all_tags.select { |tag| @options[:between_tags].include? tag }
end
filtered_tags
end
# General filtered function # General filtered function
# #
# @param [Array] all_issues # @param [Array] all_issues

View File

@ -0,0 +1,53 @@
module GitHubChangelogGenerator
class Generator
# fetch, filter tags, fetch dates and sort them in time order
def fetch_and_filter_tags
@all_tags = get_filtered_tags(@fetcher.get_all_tags)
fetch_tags_dates
sort_tags_by_date
end
# Sort all tags by date
def sort_tags_by_date
puts "Sorting tags..." if @options[:verbose]
@all_tags.sort_by! { |x| @fetcher.get_time_of_tag(x) }.reverse!
end
# Detect link, name and time for specified tag.
#
# @param [Hash] newer_tag newer tag. Can be nil, if it's Unreleased section.
# @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)
# if it's future release tag - set this value
if newer_tag.nil? && @options[:future_release]
newer_tag_name = @options[:future_release]
newer_tag_link = @options[:future_release]
else
# 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_link = newer_tag.nil? ? "HEAD" : newer_tag_name
end
[newer_tag_link, newer_tag_name, newer_tag_time]
end
# Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags
#
# @return [Array]
def get_filtered_tags(all_tags)
all_tags = all_tags
filtered_tags = all_tags
if @options[:between_tags]
@options[:between_tags].each do |tag|
unless all_tags.include? tag
puts "Warning: can't find tag #{tag}, specified with --between-tags option.".yellow
end
end
filtered_tags = all_tags.select { |tag| @options[:between_tags].include? tag }
end
filtered_tags
end
end
end

View File

@ -5,34 +5,32 @@ require_relative "version"
module GitHubChangelogGenerator module GitHubChangelogGenerator
class Parser class Parser
# parse options with optparse
def self.parse_options def self.parse_options
options = { options = get_default_options
tag1: nil,
tag2: nil,
date_format: "%Y-%m-%d",
output: "CHANGELOG.md",
issues: true,
add_issues_wo_labels: true,
add_pr_wo_labels: true,
pulls: true,
filter_issues_by_milestone: true,
author: true,
unreleased: true,
unreleased_label: "Unreleased",
compare_link: true,
include_labels: %w(bug enhancement),
exclude_labels: %w(duplicate question invalid wontfix),
max_issues: nil,
simple_list: false,
verbose: true,
merge_prefix: "**Merged pull requests:**", parser = setup_parser(options)
issue_prefix: "**Closed issues:**",
bug_prefix: "**Fixed bugs:**",
enhancement_prefix: "**Implemented enhancements:**",
git_remote: "origin"
}
parser.parse!
detect_user_and_project(options)
if !options[:user] || !options[:project]
puts parser.banner
exit
end
if options[:verbose]
puts "Performing task with options:"
pp options
puts ""
end
options
end
# setup parsing options
def self.setup_parser(options)
parser = OptionParser.new do |opts| parser = OptionParser.new do |opts|
opts.banner = "Usage: github_changelog_generator [options]" opts.banner = "Usage: github_changelog_generator [options]"
opts.on("-u", "--user [USER]", "Username of the owner of target GitHub repo") do |last| opts.on("-u", "--user [USER]", "Username of the owner of target GitHub repo") do |last|
@ -86,6 +84,9 @@ module GitHubChangelogGenerator
opts.on("--exclude-labels x,y,z", Array, 'Issues with the specified labels will be always excluded from changelog. Default is \'duplicate,question,invalid,wontfix\'') do |list| opts.on("--exclude-labels x,y,z", Array, 'Issues with the specified labels will be always excluded from changelog. Default is \'duplicate,question,invalid,wontfix\'') do |list|
options[:exclude_labels] = list options[:exclude_labels] = list
end end
opts.on("--between-tags x,y,z", Array, "Change log will be filed only between specified tags") do |list|
options[:between_tags] = list
end
opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max| opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max|
options[:max_issues] = max options[:max_issues] = max
end end
@ -113,25 +114,41 @@ module GitHubChangelogGenerator
exit exit
end end
end end
parser
parser.parse!
detect_user_and_project(options)
if !options[:user] || !options[:project]
puts parser.banner
exit
end end
if options[:verbose] # just get default options
puts "Performing task with options:" def self.get_default_options
pp options options = {
puts "" tag1: nil,
end tag2: nil,
date_format: "%Y-%m-%d",
output: "CHANGELOG.md",
issues: true,
add_issues_wo_labels: true,
add_pr_wo_labels: true,
pulls: true,
filter_issues_by_milestone: true,
author: true,
unreleased: true,
unreleased_label: "Unreleased",
compare_link: true,
include_labels: %w(bug enhancement),
exclude_labels: %w(duplicate question invalid wontfix),
max_issues: nil,
simple_list: false,
verbose: true,
merge_prefix: "**Merged pull requests:**",
issue_prefix: "**Closed issues:**",
bug_prefix: "**Fixed bugs:**",
enhancement_prefix: "**Implemented enhancements:**",
git_remote: "origin"
}
options options
end end
# Detects user and project from git
def self.detect_user_and_project(options) def self.detect_user_and_project(options)
options[:user], options[:project] = user_project_from_option(ARGV[0], ARGV[1], options[:github_site]) options[:user], options[:project] = user_project_from_option(ARGV[0], ARGV[1], options[:github_site])
if !options[:user] || !options[:project] if !options[:user] || !options[:project]