From 6d45d90a5f8804f1a1d059494349dfec28c8eaea Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 2 Jul 2016 15:29:23 +0200 Subject: [PATCH] Drop Hashie dependency --- .../generator/generator_tags.rb | 27 ++++++++++--------- .../octo_fetcher.rb | 3 ++- spec/unit/generator/generator_tags_spec.rb | 4 ++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index eefd60f..d9507a6 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -40,21 +40,22 @@ module GitHubChangelogGenerator end.reverse! end - # Try to find tag date in local hash. - # Otherwise fFetch tag time and put it to local hash file. - # @param [Hash] tag_name name of the tag + # Returns date for given GitHub Tag hash + # + # Memoize the date by tag name. + # + # @param [Hash] tag_hash + # # @return [Time] time of specified tag def get_time_of_tag(tag_name) raise ChangelogGeneratorError, "tag_name is nil" if tag_name.nil? - name_of_tag = tag_name["name"] - time_for_name = @tag_times_hash[name_of_tag] - if !time_for_name.nil? - time_for_name - else - time_string = @fetcher.fetch_date_of_tag tag_name + name_of_tag = tag_hash.fetch("name") + time_for_tag_name = @tag_times_hash[name_of_tag] + return time_for_tag_name if time_for_tag_name + + @fetcher.fetch_date_of_tag(tag_hash).tap do |time_string| @tag_times_hash[name_of_tag] = time_string - time_string end end @@ -147,11 +148,11 @@ module GitHubChangelogGenerator # @return [Array] filtered tags according :between_tags option def filter_between_tags(all_tags) filtered_tags = all_tags - tag_names = filtered_tags.map{ |ft| ft['name'] } + tag_names = filtered_tags.map { |ft| ft['name'] } if @options[:between_tags] @options[:between_tags].each do |tag| - unless tag_names.include? tag + unless tag_names.include?(tag) Helper.log.warn "Warning: can't find tag #{tag}, specified with --between-tags option." end end @@ -207,7 +208,7 @@ module GitHubChangelogGenerator end def warn_if_tag_not_found(all_tags, tag) - unless all_tags.map { |t| t["name"] }.include? tag + unless all_tags.map { |t| t["name"] }.include?(tag) Helper.log.warn "Warning: can't find tag #{tag}, specified with --exclude-tags option." end end diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index d13ad4b..3d6d258 100644 --- a/lib/github_changelog_generator/octo_fetcher.rb +++ b/lib/github_changelog_generator/octo_fetcher.rb @@ -200,7 +200,8 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow # Fetch tag time from repo # - # @param [Hash] tag + # @param [Hash] tag GitHub data item about a Tag + # # @return [Time] time of specified tag def fetch_date_of_tag(tag) commit_data = check_github_response { @client.commit(user_project, tag["commit"]["sha"]) } diff --git a/spec/unit/generator/generator_tags_spec.rb b/spec/unit/generator/generator_tags_spec.rb index 0a1a083..dee058e 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true describe GitHubChangelogGenerator::Generator do def tag_with_name(tag) - {}.tap { |mash_tag| mash_tag["name"] = tag } + { + 'name' => tag + } end def tags_from_strings(tags_strings)