refacktoring. move separation logic in funciton

This commit is contained in:
Petr Korolev 2015-05-22 13:34:01 +03:00
parent 3fc3e3e143
commit 944adc92cd
2 changed files with 49 additions and 35 deletions

View File

@ -1,13 +1,13 @@
# This configuration was generated by `rubocop --auto-gen-config` # This configuration was generated by `rubocop --auto-gen-config`
# on 2015-05-14 16:51:06 +0300 using RuboCop version 0.31.0. # on 2015-05-22 13:30:52 +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: 15 # Offense count: 17
Metrics/AbcSize: Metrics/AbcSize:
Enabled: false Max: 73
# Offense count: 2 # Offense count: 2
Metrics/BlockNesting: Metrics/BlockNesting:
@ -16,16 +16,16 @@ Metrics/BlockNesting:
# Offense count: 3 # Offense count: 3
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ClassLength: Metrics/ClassLength:
Max: 337 Max: 345
# Offense count: 5 # Offense count: 5
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 15 Max: 15
# Offense count: 22 # Offense count: 24
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/MethodLength: Metrics/MethodLength:
Enabled: false Max: 121
# Offense count: 5 # Offense count: 5
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
@ -41,7 +41,7 @@ Style/AccessorMethodName:
Style/AndOr: Style/AndOr:
Enabled: false Enabled: false
# Offense count: 19 # Offense count: 18
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
Style/BlockDelimiters: Style/BlockDelimiters:
@ -51,12 +51,12 @@ Style/BlockDelimiters:
Style/Documentation: Style/Documentation:
Enabled: false Enabled: false
# Offense count: 5 # Offense count: 3
# Configuration parameters: MinBodyLength. # Configuration parameters: MinBodyLength.
Style/GuardClause: Style/GuardClause:
Enabled: false Enabled: false
# Offense count: 15 # Offense count: 14
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: MaxLineLength. # Configuration parameters: MaxLineLength.
Style/IfUnlessModifier: Style/IfUnlessModifier:

View File

@ -161,12 +161,15 @@ module GitHubChangelogGenerator
# @param [Array] issues to filter # @param [Array] issues to filter
# @return [Array] filtered array of issues # @return [Array] filtered array of issues
def include_issues_by_labels(issues) def include_issues_by_labels(issues)
filtered_issues = @options[:include_labels].nil? ? issues : issues.select { |issue| (issue.labels.map(&:name) & @options[:include_labels]).any? } filtered_issues = @options[:include_labels].nil? ? issues : issues.select do |issue|
labels = issue.labels.map(&:name) & @options[:include_labels]
(labels).any?
end
if @options[:add_issues_wo_labels] if @options[:add_issues_wo_labels]
issues_wo_labels = issues.select { |issue| issues_wo_labels = issues.select do |issue|
!issue.labels.map(&:name).any? !issue.labels.map(&:name).any?
} end
filtered_issues |= issues_wo_labels filtered_issues |= issues_wo_labels
end end
filtered_issues filtered_issues
@ -178,7 +181,8 @@ module GitHubChangelogGenerator
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 { |issue|
!(issue.labels.map(&:name) & @options[:exclude_labels]).any? var = issue.labels.map(&:name) & @options[:exclude_labels]
!(var).any?
} }
end end
issues issues
@ -405,6 +409,27 @@ module GitHubChangelogGenerator
if @options[:issues] if @options[:issues]
# Generate issues: # Generate issues:
bugs_a, enhancement_a, issues_a = parse_by_sections(issues)
log += generate_sub_section(enhancement_a, @options[:enhancement_prefix])
log += generate_sub_section(bugs_a, @options[:bug_prefix])
log += generate_sub_section(issues_a, @options[:issue_prefix])
end
if @options[:pulls]
# Generate pull requests:
log += generate_sub_section(pull_requests, @options[:merge_prefix])
end
log
end
# This method sort issues by types
# (bugs, features, or just closed issues) by labels
#
# @param [Array] issues
# @return [Array] tuple of filtered arrays: (Bugs, Enhancements Issues)
def parse_by_sections(issues)
issues_a = [] issues_a = []
enhancement_a = [] enhancement_a = []
bugs_a = [] bugs_a = []
@ -427,18 +452,7 @@ module GitHubChangelogGenerator
issues_a.push dict issues_a.push dict
end end
} }
[bugs_a, enhancement_a, issues_a]
log += generate_sub_section(enhancement_a, @options[:enhancement_prefix])
log += generate_sub_section(bugs_a, @options[:bug_prefix])
log += generate_sub_section(issues_a, @options[:issue_prefix])
end
if @options[:pulls]
# Generate pull requests:
log += generate_sub_section(pull_requests, @options[:merge_prefix])
end
log
end end
# @param [Array] issues List of issues on sub-section # @param [Array] issues List of issues on sub-section