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`
# 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
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@ -16,13 +16,13 @@ Metrics/BlockNesting:
# Offense count: 3
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 294
Max: 280
# Offense count: 5
Metrics/CyclomaticComplexity:
Max: 15
# Offense count: 24
# Offense count: 23
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 121
@ -35,39 +35,15 @@ Metrics/PerceivedComplexity:
Style/AccessorMethodName:
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
Style/Documentation:
Enabled: false
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/EmptyLinesAroundClassBody:
Enabled: false
# Offense count: 3
# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Enabled: false
# Offense count: 14
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Enabled: false
# Offense count: 2
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
Style/Next:

View File

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

View File

@ -41,9 +41,7 @@ module GitHubChangelogGenerator
def fetch_github_token
env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil)
unless env_var
@logger.warn NO_TOKEN_PROVIDED.yellow
end
@logger.warn NO_TOKEN_PROVIDED.yellow unless env_var
env_var
end
@ -51,9 +49,7 @@ module GitHubChangelogGenerator
# Fetch all tags from repo
# @return [Array] array of tags
def get_all_tags
if @options[:verbose]
print "Fetching tags...\r"
end
print "Fetching tags...\r" if @options[:verbose]
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)
# @return [Tuple] with (issues, pull-requests)
def fetch_closed_issues_and_pr
if @options[:verbose]
print "Fetching closed issues...\r"
end
print "Fetching closed issues...\r" if @options[:verbose]
issues = []
begin

View File

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

View File

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