diff --git a/lib/github_changelog_generator/generator/generator_processor.rb b/lib/github_changelog_generator/generator/generator_processor.rb index 1e9c094..05efedb 100644 --- a/lib/github_changelog_generator/generator/generator_processor.rb +++ b/lib/github_changelog_generator/generator/generator_processor.rb @@ -77,7 +77,7 @@ module GitHubChangelogGenerator issues.select do |issue| if issue[hash_key] - time = Time.parse(issue[hash_key]).utc + time = Time.parse(issue[hash_key].to_s).utc tag_in_range_old = tag_newer_old_tag?(older_tag_time, time) diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index 3b4b207..b0defe4 100644 --- a/lib/github_changelog_generator/octo_fetcher.rb +++ b/lib/github_changelog_generator/octo_fetcher.rb @@ -3,7 +3,7 @@ module GitHubChangelogGenerator # (such as filtering, validating, e.t.c) # # Example: - # fetcher = GitHubChangelogGenerator::Fetcher.new options + # fetcher = GitHubChangelogGenerator::OctoFetcher.new options class OctoFetcher PER_PAGE_NUMBER = 100 @@ -31,18 +31,6 @@ module GitHubChangelogGenerator @client = client_type.new(@github_options) end - # Returns GitHub token. First try to use variable, provided by --token option, - # otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable. - # - # @return [String] - def fetch_github_token - env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil) - - Helper.log.warn NO_TOKEN_PROVIDED.yellow unless env_var - - env_var - end - # Fetch all tags from repo # # @return [Array] array of tags @@ -52,27 +40,6 @@ module GitHubChangelogGenerator check_github_response { github_fetch_tags } end - # This is wrapper with rescue block - # - # @return [Object] returns exactly the same, what you put in the block, but wrap it with begin-rescue block - def check_github_response - begin - value = yield - rescue Github::Error::Unauthorized => e - Helper.log.error e.body.red - abort "Error: wrong GitHub token" - rescue Github::Error::Forbidden => e - Helper.log.warn e.body.red - Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow - end - value - end - - # @return [String] helper to return Github "user/project" - def user_project - "#{@options[:user]}/#{@options[:project]}" - end - # Parses a URI and returns a hash of all GET variables # # @param [String] uri eg. https://api.github.com/repositories/43914960/tags?page=37&foo=1 @@ -100,39 +67,6 @@ module GitHubChangelogGenerator end end - # Iterates through all pages until there are no more :next pages to follow - # yields the result per page - # - # @param [Octokit::Client] client - # @param [String] method (eg. 'tags') - # @return [Integer] total number of pages - def iterate_pages(client, method, *args, &block) - if args.size == 1 && args.first.is_a?(Hash) - request_options = args.delete_at(0) - elsif args.size > 1 && args.last.is_a?(Hash) - request_options = args.delete_at(args.length - 1) - end - - args.push(@request_options.merge(request_options)) - # args.push({}.merge(request_options)) - - pages = 1 - client.send(method, user_project, *args) - # client.send(method, 'retentionscience/rsapi', *args) - last_response = client.last_response - - yield last_response.data - - while !(next_one = last_response.rels[:next]).nil? - pages +=1 - - last_response = next_one.get - yield last_response.data - end - - pages - end - # Fill input array with tags # @@ -225,18 +159,6 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow pull_requests end - # Print specified line on the same string - # - # @param [String] log_string - def print_in_same_line(log_string) - print log_string + "\r" - end - - # Print long line with spaces on same line to clear prev message - def print_empty_line - print_in_same_line(" ") - end - # Fetch event for all issues and add them to :events # # @param [Array] issues @@ -289,5 +211,83 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow def fetch_commit(event) @client.commit(user_project, event[:commit_id]) end + + private + + # Iterates through all pages until there are no more :next pages to follow + # yields the result per page + # + # @param [Octokit::Client] client + # @param [String] method (eg. 'tags') + # @return [Integer] total number of pages + def iterate_pages(client, method, *args, &block) + if args.size == 1 && args.first.is_a?(Hash) + request_options = args.delete_at(0) + elsif args.size > 1 && args.last.is_a?(Hash) + request_options = args.delete_at(args.length - 1) + end + + args.push(@request_options.merge(request_options)) + + pages = 1 + client.send(method, user_project, *args) + last_response = client.last_response + + yield last_response.data + + while !(next_one = last_response.rels[:next]).nil? + pages +=1 + + last_response = next_one.get + yield last_response.data + end + + pages + end + + # This is wrapper with rescue block + # + # @return [Object] returns exactly the same, what you put in the block, but wrap it with begin-rescue block + def check_github_response + begin + value = yield + rescue Github::Error::Unauthorized => e + Helper.log.error e.body.red + abort "Error: wrong GitHub token" + rescue Github::Error::Forbidden => e + Helper.log.warn e.body.red + Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow + end + value + end + + # Print specified line on the same string + # + # @param [String] log_string + def print_in_same_line(log_string) + print log_string + "\r" + end + + # Print long line with spaces on same line to clear prev message + def print_empty_line + print_in_same_line(" ") + end + + # Returns GitHub token. First try to use variable, provided by --token option, + # otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable. + # + # @return [String] + def fetch_github_token + env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil) + + Helper.log.warn NO_TOKEN_PROVIDED.yellow unless env_var + + env_var + end + + # @return [String] helper to return Github "user/project" + def user_project + "#{@options[:user]}/#{@options[:project]}" + end end end