move compund to generator

This commit is contained in:
Petr Korolev 2015-05-22 14:11:29 +03:00
parent 7f696b6b09
commit 4a96a7c0c9
3 changed files with 51 additions and 45 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 14:06:42 +0300 using RuboCop version 0.31.0. # on 2015-05-22 14:05:01 +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,7 +16,7 @@ Metrics/BlockNesting:
# Offense count: 3 # Offense count: 3
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ClassLength: Metrics/ClassLength:
Max: 350 Max: 321
# Offense count: 5 # Offense count: 5
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
@ -51,6 +51,17 @@ Style/BlockDelimiters:
Style/Documentation: Style/Documentation:
Enabled: false Enabled: false
# Offense count: 2
# Cop supports --auto-correct.
Style/EmptyLines:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/EmptyLinesAroundClassBody:
Enabled: false
# Offense count: 3 # Offense count: 3
# Configuration parameters: MinBodyLength. # Configuration parameters: MinBodyLength.
Style/GuardClause: Style/GuardClause:
@ -72,8 +83,3 @@ Style/Next:
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
Style/RegexpLiteral: Style/RegexpLiteral:
Enabled: false Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
Style/TrailingWhitespace:
Enabled: false

View File

@ -191,7 +191,7 @@ module GitHubChangelogGenerator
# The entry point of this script to generate change log # The entry point of this script to generate change log
# @raise (ChangelogGeneratorError) Is thrown when one of specified tags was not found in list of tags. # @raise (ChangelogGeneratorError) Is thrown when one of specified tags was not found in list of tags.
def run def run
log = compound_changelog log = @generator.compound_changelog
output_filename = "#{@options[:output]}" output_filename = "#{@options[:output]}"
File.open(output_filename, "w") { |file| file.write(log) } File.open(output_filename, "w") { |file| file.write(log) }
@ -199,42 +199,6 @@ module GitHubChangelogGenerator
puts "Generated log placed in #{Dir.pwd}/#{output_filename}" puts "Generated log placed in #{Dir.pwd}/#{output_filename}"
end end
# Main function to start change log generation
#
# @return [String] Generated change log file
def compound_changelog
log = "# Change Log\n\n"
if @options[:unreleased_only]
log += generate_log_between_tags(all_tags[0], nil)
elsif @options[:tag1] and @options[:tag2]
tag1 = @options[:tag1]
tag2 = @options[:tag2]
tags_strings = []
all_tags.each { |x| tags_strings.push(x["name"]) }
if tags_strings.include?(tag1)
if tags_strings.include?(tag2)
to_a = tags_strings.map.with_index.to_a
hash = Hash[to_a]
index1 = hash[tag1]
index2 = hash[tag2]
log += generate_log_between_tags(all_tags[index1], all_tags[index2])
else
fail ChangelogGeneratorError, "Can't find tag #{tag2} -> exit".red
end
else
fail ChangelogGeneratorError, "Can't find tag #{tag1} -> exit".red
end
else
log += generate_log_for_all_tags
end
log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
@log = log
@log = log
end
# The full cycle of generation for whole project # The full cycle of generation for whole project
# @return [String] The complete change log # @return [String] The complete change log
def generate_log_for_all_tags def generate_log_for_all_tags

View File

@ -49,6 +49,42 @@ module GitHubChangelogGenerator
string string
end end
# Main function to start change log generation
#
# @return [String] Generated change log file
def compound_changelog
log = "# Change Log\n\n"
if @options[:unreleased_only]
log += generate_log_between_tags(all_tags[0], nil)
elsif @options[:tag1] and @options[:tag2]
tag1 = @options[:tag1]
tag2 = @options[:tag2]
tags_strings = []
all_tags.each { |x| tags_strings.push(x["name"]) }
if tags_strings.include?(tag1)
if tags_strings.include?(tag2)
to_a = tags_strings.map.with_index.to_a
hash = Hash[to_a]
index1 = hash[tag1]
index2 = hash[tag2]
log += generate_log_between_tags(all_tags[index1], all_tags[index2])
else
fail ChangelogGeneratorError, "Can't find tag #{tag2} -> exit".red
end
else
fail ChangelogGeneratorError, "Can't find tag #{tag1} -> exit".red
end
else
log += generate_log_for_all_tags
end
log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
@log = log
@log = log
end
end end
end end