Drop Hashie dependency

This commit is contained in:
Olle Jonsson 2016-07-02 15:29:23 +02:00
parent 3df84403c4
commit 6d45d90a5f
3 changed files with 19 additions and 15 deletions

View File

@ -40,21 +40,22 @@ module GitHubChangelogGenerator
end.reverse! end.reverse!
end end
# Try to find tag date in local hash. # Returns date for given GitHub Tag hash
# Otherwise fFetch tag time and put it to local hash file. #
# @param [Hash] tag_name name of the tag # Memoize the date by tag name.
#
# @param [Hash] tag_hash
#
# @return [Time] time of specified tag # @return [Time] time of specified tag
def get_time_of_tag(tag_name) def get_time_of_tag(tag_name)
raise ChangelogGeneratorError, "tag_name is nil" if tag_name.nil? raise ChangelogGeneratorError, "tag_name is nil" if tag_name.nil?
name_of_tag = tag_name["name"] name_of_tag = tag_hash.fetch("name")
time_for_name = @tag_times_hash[name_of_tag] time_for_tag_name = @tag_times_hash[name_of_tag]
if !time_for_name.nil? return time_for_tag_name if time_for_tag_name
time_for_name
else @fetcher.fetch_date_of_tag(tag_hash).tap do |time_string|
time_string = @fetcher.fetch_date_of_tag tag_name
@tag_times_hash[name_of_tag] = time_string @tag_times_hash[name_of_tag] = time_string
time_string
end end
end end
@ -151,7 +152,7 @@ module GitHubChangelogGenerator
if @options[:between_tags] if @options[:between_tags]
@options[:between_tags].each do |tag| @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." Helper.log.warn "Warning: can't find tag #{tag}, specified with --between-tags option."
end end
end end
@ -207,7 +208,7 @@ module GitHubChangelogGenerator
end end
def warn_if_tag_not_found(all_tags, tag) 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." Helper.log.warn "Warning: can't find tag #{tag}, specified with --exclude-tags option."
end end
end end

View File

@ -200,7 +200,8 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
# Fetch tag time from repo # Fetch tag time from repo
# #
# @param [Hash] tag # @param [Hash] tag GitHub data item about a Tag
#
# @return [Time] time of specified tag # @return [Time] time of specified tag
def fetch_date_of_tag(tag) def fetch_date_of_tag(tag)
commit_data = check_github_response { @client.commit(user_project, tag["commit"]["sha"]) } commit_data = check_github_response { @client.commit(user_project, tag["commit"]["sha"]) }

View File

@ -1,7 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
describe GitHubChangelogGenerator::Generator do describe GitHubChangelogGenerator::Generator do
def tag_with_name(tag) def tag_with_name(tag)
{}.tap { |mash_tag| mash_tag["name"] = tag } {
'name' => tag
}
end end
def tags_from_strings(tags_strings) def tags_from_strings(tags_strings)