rubocop autofixes

This commit is contained in:
Petr Korolev 2015-05-22 15:59:29 +03:00
parent cf7ae57e3d
commit 9a24eb1cb3
5 changed files with 54 additions and 110 deletions

View File

@ -1,5 +1,5 @@
# This configuration was generated by `rubocop --auto-gen-config` # This configuration was generated by `rubocop --auto-gen-config`
# on 2015-05-22 15:54:38 +0300 using RuboCop version 0.31.0. # on 2015-05-22 15:59:03 +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
@ -16,13 +16,13 @@ Metrics/BlockNesting:
# Offense count: 3 # Offense count: 3
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ClassLength: Metrics/ClassLength:
Max: 294 Max: 280
# Offense count: 5 # Offense count: 5
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 15 Max: 15
# Offense count: 24 # Offense count: 23
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/MethodLength: Metrics/MethodLength:
Max: 121 Max: 121
@ -35,39 +35,15 @@ Metrics/PerceivedComplexity:
Style/AccessorMethodName: Style/AccessorMethodName:
Enabled: false Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/AndOr:
Enabled: false
# Offense count: 18
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
Style/BlockDelimiters:
Enabled: false
# Offense count: 6 # Offense count: 6
Style/Documentation: Style/Documentation:
Enabled: false Enabled: false
# Offense count: 4 # Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/EmptyLinesAroundClassBody:
Enabled: false
# Offense count: 3
# Configuration parameters: MinBodyLength. # Configuration parameters: MinBodyLength.
Style/GuardClause: Style/GuardClause:
Enabled: false Enabled: false
# Offense count: 14
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Enabled: false
# Offense count: 2 # Offense count: 2
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
Style/Next: Style/Next:

View File

@ -13,7 +13,6 @@ require_relative "github_changelog_generator/reader"
module GitHubChangelogGenerator module GitHubChangelogGenerator
# Main class and entry point for this script. # Main class and entry point for this script.
class ChangelogGenerator class ChangelogGenerator
# Class, responsible for whole change log generation cycle # Class, responsible for whole change log generation cycle
# @return initialised instance of ChangelogGenerator # @return initialised instance of ChangelogGenerator
def initialize def initialize
@ -31,7 +30,6 @@ module GitHubChangelogGenerator
puts "Done!" puts "Done!"
puts "Generated log placed in #{Dir.pwd}/#{output_filename}" puts "Generated log placed in #{Dir.pwd}/#{output_filename}"
end end
end end
if __FILE__ == $PROGRAM_NAME if __FILE__ == $PROGRAM_NAME

View File

@ -41,9 +41,7 @@ module GitHubChangelogGenerator
def fetch_github_token def fetch_github_token
env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil) env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil)
unless env_var @logger.warn NO_TOKEN_PROVIDED.yellow unless env_var
@logger.warn NO_TOKEN_PROVIDED.yellow
end
env_var env_var
end end
@ -51,9 +49,7 @@ module GitHubChangelogGenerator
# Fetch all tags from repo # Fetch all tags from repo
# @return [Array] array of tags # @return [Array] array of tags
def get_all_tags def get_all_tags
if @options[:verbose] print "Fetching tags...\r" if @options[:verbose]
print "Fetching tags...\r"
end
tags = [] tags = []
@ -98,9 +94,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
# (pull request is kind of issue in term of GitHub) # (pull request is kind of issue in term of GitHub)
# @return [Tuple] with (issues, pull-requests) # @return [Tuple] with (issues, pull-requests)
def fetch_closed_issues_and_pr def fetch_closed_issues_and_pr
if @options[:verbose] print "Fetching closed issues...\r" if @options[:verbose]
print "Fetching closed issues...\r"
end
issues = [] issues = []
begin begin

View File

@ -80,7 +80,7 @@ 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] and @options[:tag2] elsif @options[:tag1] && @options[:tag2]
tag1 = @options[:tag1] tag1 = @options[:tag1]
tag2 = @options[:tag2] tag2 = @options[:tag2]
tags_strings = [] tags_strings = []
@ -110,31 +110,27 @@ module GitHubChangelogGenerator
# Async fetching of all tags dates # Async fetching of all tags dates
def fetch_tags_dates def fetch_tags_dates
if @options[:verbose] print "Fetching tag dates...\r" if @options[:verbose]
print "Fetching tag dates...\r"
end
# Async fetching tags: # Async fetching tags:
threads = [] threads = []
i = 0 i = 0
all = @all_tags.count all = @all_tags.count
@all_tags.each { |tag| @all_tags.each do |tag|
threads << Thread.new { threads << Thread.new do
@fetcher.get_time_of_tag(tag) @fetcher.get_time_of_tag(tag)
if @options[:verbose] if @options[:verbose]
print "Fetching tags dates: #{i + 1}/#{all}\r" print "Fetching tags dates: #{i + 1}/#{all}\r"
i += 1 i += 1
end end
} end
} end
print " \r" print " \r"
threads.each(&:join) threads.each(&:join)
if @options[:verbose] puts "Fetching tags dates: #{i}" if @options[:verbose]
puts "Fetching tags dates: #{i}"
end
end end
# Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags # Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags
@ -155,28 +151,24 @@ module GitHubChangelogGenerator
end end
def detect_actual_closed_dates def detect_actual_closed_dates
if @options[:verbose] print "Fetching closed dates for issues...\r" if @options[:verbose]
print "Fetching closed dates for issues...\r"
end
threads = [] threads = []
@issues.each { |issue| @issues.each do |issue|
threads << Thread.new { threads << Thread.new do
find_closed_date_by_commit(issue) find_closed_date_by_commit(issue)
} end
} end
@pull_requests.each { |pull_request| @pull_requests.each do |pull_request|
threads << Thread.new { threads << Thread.new do
find_closed_date_by_commit(pull_request) find_closed_date_by_commit(pull_request)
} end
} end
threads.each(&:join) threads.each(&:join)
if @options[:verbose] puts "Fetching closed dates for issues: Done!" if @options[:verbose]
puts "Fetching closed dates for issues: Done!"
end
end end
# Fill :actual_date parameter of specified issue by closed date of the commit, it it was closed by commit. # Fill :actual_date parameter of specified issue by closed date of the commit, it it was closed by commit.
@ -186,7 +178,7 @@ module GitHubChangelogGenerator
# if it's PR -> then find "merged event", in case of usual issue -> fond closed date # if it's PR -> then find "merged event", in case of usual issue -> fond closed date
compare_string = issue[:merged_at].nil? ? "closed" : "merged" compare_string = issue[:merged_at].nil? ? "closed" : "merged"
# reverse! - to find latest closed event. (event goes in date order) # reverse! - to find latest closed event. (event goes in date order)
issue["events"].reverse!.each { |event| issue["events"].reverse!.each do |event|
if event[:event].eql? compare_string if event[:event].eql? compare_string
if event[:commit_id].nil? if event[:commit_id].nil?
issue[:actual_date] = issue[:closed_at] issue[:actual_date] = issue[:closed_at]
@ -201,7 +193,7 @@ module GitHubChangelogGenerator
end end
break break
end end
} end
end end
# TODO: assert issues, that remain without 'actual_date' hash for some reason. # TODO: assert issues, that remain without 'actual_date' hash for some reason.
end end
@ -233,18 +225,16 @@ 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 def filter_merged_pull_requests
if @options[:verbose] print "Fetching merged dates...\r" if @options[:verbose]
print "Fetching merged dates...\r"
end
pull_requests = @fetcher.fetch_closed_pull_requests pull_requests = @fetcher.fetch_closed_pull_requests
@pull_requests.each { |pr| @pull_requests.each do |pr|
fetched_pr = pull_requests.find { |fpr| fetched_pr = pull_requests.find do |fpr|
fpr.number == pr.number fpr.number == pr.number
} end
pr[:merged_at] = fetched_pr[:merged_at] pr[:merged_at] = fetched_pr[:merged_at]
pull_requests.delete(fetched_pr) pull_requests.delete(fetched_pr)
} end
@pull_requests.select! do |pr| @pull_requests.select! do |pr|
!pr[:merged_at].nil? !pr[:merged_at].nil?
@ -274,16 +264,16 @@ module GitHubChangelogGenerator
# @return [Array] filtered array # @return [Array] filtered array
def exclude_issues_by_labels(issues) def exclude_issues_by_labels(issues)
unless @options[:exclude_labels].nil? unless @options[:exclude_labels].nil?
issues = issues.select { |issue| issues = issues.select do |issue|
var = issue.labels.map(&:name) & @options[:exclude_labels] var = issue.labels.map(&:name) & @options[:exclude_labels]
!(var).any? !(var).any?
} end
end end
issues issues
end end
def filter_by_milestone(filtered_issues, newer_tag_name, src_array) def filter_by_milestone(filtered_issues, newer_tag_name, src_array)
filtered_issues.select! { |issue| filtered_issues.select! do |issue|
# leave issues without milestones # leave issues without milestones
if issue.milestone.nil? if issue.milestone.nil?
true true
@ -291,18 +281,18 @@ module GitHubChangelogGenerator
# check, that this milestone in tag list: # check, that this milestone in tag list:
@all_tags.find { |tag| tag.name == issue.milestone.title }.nil? @all_tags.find { |tag| tag.name == issue.milestone.title }.nil?
end end
} end
unless newer_tag_name.nil? unless newer_tag_name.nil?
# add missed issues (according milestones) # add missed issues (according milestones)
issues_to_add = src_array.select { |issue| issues_to_add = src_array.select do |issue|
if issue.milestone.nil? if issue.milestone.nil?
false false
else else
# check, that this milestone in tag list: # check, that this milestone in tag list:
milestone_is_tag = @all_tags.find { |tag| milestone_is_tag = @all_tags.find do |tag|
tag.name == issue.milestone.title tag.name == issue.milestone.title
} end
if milestone_is_tag.nil? if milestone_is_tag.nil?
false false
@ -310,7 +300,7 @@ module GitHubChangelogGenerator
issue.milestone.title == newer_tag_name issue.milestone.title == newer_tag_name
end end
end end
} end
filtered_issues |= issues_to_add filtered_issues |= issues_to_add
end end
@ -329,7 +319,7 @@ module GitHubChangelogGenerator
newer_tag_time = newer_tag && @fetcher.get_time_of_tag(newer_tag) newer_tag_time = newer_tag && @fetcher.get_time_of_tag(newer_tag)
older_tag_time = older_tag && @fetcher.get_time_of_tag(older_tag) older_tag_time = older_tag && @fetcher.get_time_of_tag(older_tag)
array.select { |req| array.select do |req|
if req[hash_key] if req[hash_key]
t = Time.parse(req[hash_key]).utc t = Time.parse(req[hash_key]).utc
@ -351,7 +341,7 @@ module GitHubChangelogGenerator
else else
false false
end end
} end
end end
# Generates log for section with header and body # Generates log for section with header and body
@ -403,9 +393,9 @@ module GitHubChangelogGenerator
enhancement_a = [] enhancement_a = []
bugs_a = [] bugs_a = []
issues.each { |dict| issues.each do |dict|
added = false added = false
dict.labels.each { |label| dict.labels.each do |label|
if label.name == "bug" if label.name == "bug"
bugs_a.push dict bugs_a.push dict
added = true added = true
@ -416,11 +406,9 @@ module GitHubChangelogGenerator
added = true added = true
next next
end end
}
unless added
issues_a.push dict
end end
} issues_a.push dict unless added
end
[bugs_a, enhancement_a, issues_a] [bugs_a, enhancement_a, issues_a]
end end
@ -431,12 +419,9 @@ module GitHubChangelogGenerator
filtered_issues = exclude_issues_by_labels(filtered_issues) filtered_issues = exclude_issues_by_labels(filtered_issues)
if @options[:verbose] puts "Filtered issues: #{filtered_issues.count}" if @options[:verbose]
puts "Filtered issues: #{filtered_issues.count}"
end
filtered_issues filtered_issues
end end
end end
end end

View File

@ -6,15 +6,13 @@ module GitHubChangelogGenerator
def generate_sub_section(issues, prefix) def generate_sub_section(issues, prefix)
log = "" log = ""
if options[:simple_list] != true && issues.any? log += "#{prefix}\n\n" if options[:simple_list] != true && issues.any?
log += "#{prefix}\n\n"
end
if issues.any? if issues.any?
issues.each { |issue| issues.each do |issue|
merge_string = get_string_for_issue(issue) merge_string = get_string_for_issue(issue)
log += "- #{merge_string}\n\n" log += "- #{merge_string}\n\n"
} end
end end
log log
end end
@ -77,34 +75,27 @@ module GitHubChangelogGenerator
def generate_log_for_all_tags def generate_log_for_all_tags
fetch_tags_dates fetch_tags_dates
if @options[:verbose] puts "Sorting tags..." if @options[:verbose]
puts "Sorting tags..."
end
@all_tags.sort_by! { |x| @fetcher.get_time_of_tag(x) }.reverse! @all_tags.sort_by! { |x| @fetcher.get_time_of_tag(x) }.reverse!
if @options[:verbose] puts "Generating log..." if @options[:verbose]
puts "Generating log..."
end
log = "" log = ""
if @options[:unreleased] && @all_tags.count != 0 if @options[:unreleased] && @all_tags.count != 0
unreleased_log = generate_log_between_tags(all_tags[0], nil) unreleased_log = generate_log_between_tags(all_tags[0], nil)
if unreleased_log log += unreleased_log if unreleased_log
log += unreleased_log
end
end end
(1...all_tags.size).each { |index| (1...all_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
if @all_tags.count != 0 if @all_tags.count != 0
log += generate_log_between_tags(nil, all_tags.last) log += generate_log_between_tags(nil, all_tags.last)
end end
log log
end end
end end
end end