From 4e9ed5df28a91b27e2631fc8ccd1439c1f9e28c0 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 3 Apr 2015 18:59:37 +0300 Subject: [PATCH 1/3] add error class and documentation --- lib/github_changelog_generator.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index a92817e..aa7346e 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -11,6 +11,12 @@ require_relative "github_changelog_generator/version" require_relative "github_changelog_generator/reader" module GitHubChangelogGenerator + + # Default error for ChangelogGenerator + class ChangelogGeneratorError < StandardError + end + + # Main class and entry point for this script. class ChangelogGenerator attr_accessor :options, :all_tags, :github @@ -18,6 +24,8 @@ module GitHubChangelogGenerator GH_RATE_LIMIT_EXCEEDED_MSG = "Warning: GitHub API rate limit (5000 per hour) exceeded, change log may be " \ "missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument." + # Class, responsible for whole change log generation cycle + # @return initialised insance of ChangelogGenerator def initialize @options = Parser.parse_options @@ -176,6 +184,8 @@ module GitHubChangelogGenerator filtered_pull_requests end + # 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 compound_changelog log = "# Change Log\n\n" @@ -195,12 +205,10 @@ module GitHubChangelogGenerator index2 = hash[tag2] log += generate_log_between_tags(all_tags[index1], all_tags[index2]) else - puts "Can't find tag #{tag2} -> exit" - exit + raise ChangelogGeneratorError.new("Can't find tag #{tag2} -> exit") end else - puts "Can't find tag #{tag1} -> exit" - exit + raise ChangelogGeneratorError.new("Can't find tag #{tag1} -> exit") end else log += generate_log_for_all_tags @@ -317,8 +325,10 @@ module GitHubChangelogGenerator @github_token ||= env_var end + # Generate log only between 2 specified tags + # @param [String] older_tag all issues before this tag date will be excluded. May be nil, if it's first tag + # @param [String] newer_tag all issue after this tag will be excluded. May be nil for unreleased section def generate_log_between_tags(older_tag, newer_tag) - # older_tag nil - means it's first tag, newer_tag nil - means it unreleased section filtered_pull_requests = delete_by_time(@pull_requests, :actual_date, older_tag, newer_tag) filtered_issues = delete_by_time(@issues, :actual_date, older_tag, newer_tag) From 2b656c83b6d2ed585c34f566eb335b176a667b0f Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 3 Apr 2015 19:13:50 +0300 Subject: [PATCH 2/3] add doc + fix raise --- lib/github_changelog_generator.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index aa7346e..e473a32 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -205,10 +205,10 @@ module GitHubChangelogGenerator index2 = hash[tag2] log += generate_log_between_tags(all_tags[index1], all_tags[index2]) else - raise ChangelogGeneratorError.new("Can't find tag #{tag2} -> exit") + raise ChangelogGeneratorError, "Can't find tag #{tag2} -> exit".red end else - raise ChangelogGeneratorError.new("Can't find tag #{tag1} -> exit") + raise ChangelogGeneratorError, "Can't find tag #{tag1} -> exit".red end else log += generate_log_for_all_tags @@ -384,8 +384,13 @@ module GitHubChangelogGenerator filtered_issues end - def delete_by_time(array, hash_key, older_tag = nil, newer_tag = nil) - fail "At least one of the tags should be not nil!" if older_tag.nil? && newer_tag.nil? + # @param [Array] array of issues to filter + # @param [Symbol] hash_key key of date value default is :actual_date + # @param [String] older_tag all issues before this tag date will be excluded. May be nil, if it's first tag + # @param [String] newer_tag all issue after this tag will be excluded. May be nil for unreleased section + def delete_by_time(array, hash_key = :actual_date, older_tag = nil, newer_tag = nil) + + raise ChangelogGeneratorError, "At least one of the tags should be not nil!" if older_tag.nil? && newer_tag.nil? newer_tag_time = get_time_of_tag(newer_tag) older_tag_time = get_time_of_tag(older_tag) From dae68ee3b59400c13cec5ea6218a843b58ffd1d0 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Sat, 4 Apr 2015 00:08:00 +0300 Subject: [PATCH 3/3] rubocop fixes --- lib/github_changelog_generator.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index e473a32..8f227ce 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -11,7 +11,6 @@ require_relative "github_changelog_generator/version" require_relative "github_changelog_generator/reader" module GitHubChangelogGenerator - # Default error for ChangelogGenerator class ChangelogGeneratorError < StandardError end @@ -205,10 +204,10 @@ module GitHubChangelogGenerator index2 = hash[tag2] log += generate_log_between_tags(all_tags[index1], all_tags[index2]) else - raise ChangelogGeneratorError, "Can't find tag #{tag2} -> exit".red + fail ChangelogGeneratorError, "Can't find tag #{tag2} -> exit".red end else - raise ChangelogGeneratorError, "Can't find tag #{tag1} -> exit".red + fail ChangelogGeneratorError, "Can't find tag #{tag1} -> exit".red end else log += generate_log_for_all_tags @@ -389,8 +388,7 @@ module GitHubChangelogGenerator # @param [String] older_tag all issues before this tag date will be excluded. May be nil, if it's first tag # @param [String] newer_tag all issue after this tag will be excluded. May be nil for unreleased section def delete_by_time(array, hash_key = :actual_date, older_tag = nil, newer_tag = nil) - - raise ChangelogGeneratorError, "At least one of the tags should be not nil!" if older_tag.nil? && newer_tag.nil? + fail ChangelogGeneratorError, "At least one of the tags should be not nil!".red if older_tag.nil? && newer_tag.nil? newer_tag_time = get_time_of_tag(newer_tag) older_tag_time = get_time_of_tag(older_tag)