From 4a96a7c0c96f40c0fd796758ab8b43e75caa6772 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 22 May 2015 14:11:29 +0300 Subject: [PATCH] move compund to generator --- .rubocop_todo.yml | 20 +++++++---- lib/github_changelog_generator.rb | 38 +-------------------- lib/github_changelog_generator/generator.rb | 38 ++++++++++++++++++++- 3 files changed, 51 insertions(+), 45 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2c75cff..3986315 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,5 +1,5 @@ # 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 # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -16,7 +16,7 @@ Metrics/BlockNesting: # Offense count: 3 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 350 + Max: 321 # Offense count: 5 Metrics/CyclomaticComplexity: @@ -51,6 +51,17 @@ Style/BlockDelimiters: Style/Documentation: 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 # Configuration parameters: MinBodyLength. Style/GuardClause: @@ -72,8 +83,3 @@ Style/Next: # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. Style/RegexpLiteral: Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/TrailingWhitespace: - Enabled: false diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 21a055a..5dda866 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -191,7 +191,7 @@ module GitHubChangelogGenerator # 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. def run - log = compound_changelog + log = @generator.compound_changelog output_filename = "#{@options[:output]}" File.open(output_filename, "w") { |file| file.write(log) } @@ -199,42 +199,6 @@ module GitHubChangelogGenerator puts "Generated log placed in #{Dir.pwd}/#{output_filename}" 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 # @return [String] The complete change log def generate_log_for_all_tags diff --git a/lib/github_changelog_generator/generator.rb b/lib/github_changelog_generator/generator.rb index 345bc81..ac39bd6 100644 --- a/lib/github_changelog_generator/generator.rb +++ b/lib/github_changelog_generator/generator.rb @@ -49,6 +49,42 @@ module GitHubChangelogGenerator string 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