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

View File

@ -1,37 +1,37 @@
# 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
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 16
# Offense count: 14
Metrics/AbcSize:
Max: 68
Max: 57
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ClassLength:
Enabled: false
Max: 182
# Offense count: 3
# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 9
Max: 7
# Offense count: 22
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 117
Max: 84
# Offense count: 4
# Offense count: 1
Metrics/PerceivedComplexity:
Max: 12
Max: 8
# Offense count: 2
Style/AccessorMethodName:
Enabled: false
# Offense count: 6
# Offense count: 8
Style/Documentation:
Enabled: false

View File

@ -2,6 +2,7 @@ require "github_changelog_generator/fetcher"
require_relative "generator_generation"
require_relative "generator_fetcher"
require_relative "generator_processor"
require_relative "generator_tags"
module GitHubChangelogGenerator
# Default error for ChangelogGenerator
@ -21,7 +22,7 @@ module GitHubChangelogGenerator
@fetcher = GitHubChangelogGenerator::Fetcher.new @options
fetch_tags
fetch_and_filter_tags
fetch_issues_and_pr
end
@ -37,20 +38,6 @@ module GitHubChangelogGenerator
detect_actual_closed_dates(@issues + @pull_requests)
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.
#
# @param [String] string
@ -94,26 +81,6 @@ module GitHubChangelogGenerator
log
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.
#
# @param [Array] issues

View File

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

View File

@ -138,23 +138,6 @@ module GitHubChangelogGenerator
filtered_issues
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
#
# @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
class Parser
# parse options with optparse
def self.parse_options
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,
options = get_default_options
merge_prefix: "**Merged pull requests:**",
issue_prefix: "**Closed issues:**",
bug_prefix: "**Fixed bugs:**",
enhancement_prefix: "**Implemented enhancements:**",
git_remote: "origin"
}
parser = setup_parser(options)
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|
opts.banner = "Usage: github_changelog_generator [options]"
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|
options[:exclude_labels] = list
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|
options[:max_issues] = max
end
@ -113,25 +114,41 @@ module GitHubChangelogGenerator
exit
end
end
parser.parse!
detect_user_and_project(options)
if !options[:user] || !options[:project]
puts parser.banner
exit
parser
end
if options[:verbose]
puts "Performing task with options:"
pp options
puts ""
end
# just get default options
def self.get_default_options
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:**",
issue_prefix: "**Closed issues:**",
bug_prefix: "**Fixed bugs:**",
enhancement_prefix: "**Implemented enhancements:**",
git_remote: "origin"
}
options
end
# Detects user and project from git
def self.detect_user_and_project(options)
options[:user], options[:project] = user_project_from_option(ARGV[0], ARGV[1], options[:github_site])
if !options[:user] || !options[:project]