OctoFetcher: inline helper function, drop class extensions

This commit is contained in:
Olle Jonsson 2016-10-05 20:43:43 +00:00
parent 43a6e49055
commit 70aaba9aa2
4 changed files with 21 additions and 38 deletions

View File

@ -16,8 +16,6 @@ require_relative "github_changelog_generator/parser_file"
require_relative "github_changelog_generator/generator/generator"
require_relative "github_changelog_generator/version"
require_relative "github_changelog_generator/reader"
require_relative "github_changelog_generator/hash"
require_relative "github_changelog_generator/array"
# The main module, where placed all classes (now, at least)
module GitHubChangelogGenerator

View File

@ -1,14 +0,0 @@
# frozen_string_literal: true
class Array
def stringify_keys_deep!
new_ar = []
each do |value|
new_value = value
if value.is_a?(Hash) || value.is_a?(Array)
new_value = value.stringify_keys_deep!
end
new_ar << new_value
end
new_ar
end
end

View File

@ -1,16 +0,0 @@
# frozen_string_literal: true
class Hash
def stringify_keys_deep!
new_hash = {}
keys.each do |k|
ks = k.respond_to?(:to_s) ? k.to_s : k
new_hash[ks] = if values_at(k).first.is_a?(Hash) || values_at(k).first.is_a?(Array)
values_at(k).first.send(:stringify_keys_deep!)
else
values_at(k).first
end
end
new_hash
end
end

View File

@ -107,7 +107,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
Helper.log.info "Found #{tags.count} tags"
end
# tags are a Sawyer::Resource. Convert to hash
tags = tags.map { |h| h.to_hash.stringify_keys_deep! }
tags = tags.map { |h| stringify_keys_deep(h.to_hash) }
tags
end
@ -137,7 +137,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
print_empty_line
Helper.log.info "Received issues: #{issues.count}"
issues = issues.map { |h| h.to_hash.stringify_keys_deep! }
issues = issues.map { |h| stringify_keys_deep(h.to_hash) }
# separate arrays of issues and pull requests:
issues.partition do |x|
@ -168,7 +168,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
print_empty_line
Helper.log.info "Pull Request count: #{pull_requests.count}"
pull_requests = pull_requests.map { |h| h.to_hash.stringify_keys_deep! }
pull_requests = pull_requests.map { |h| stringify_keys_deep(h.to_hash) }
pull_requests
end
@ -187,7 +187,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
iterate_pages(@client, "issue_events", issue["number"], {}) do |new_event|
issue["events"].concat(new_event)
end
issue["events"] = issue["events"].map { |h| h.to_hash.stringify_keys_deep! }
issue["events"] = issue["events"].map { |h| stringify_keys_deep(h.to_hash) }
print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}")
i += 1
end
@ -209,7 +209,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
# @return [Time] time of specified tag
def fetch_date_of_tag(tag)
commit_data = check_github_response { @client.commit(user_project, tag["commit"]["sha"]) }
commit_data = commit_data.to_hash.stringify_keys_deep!
commit_data = stringify_keys_deep(commit_data.to_hash)
commit_data["commit"]["committer"]["date"]
end
@ -220,13 +220,28 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
def fetch_commit(event)
check_github_response do
commit = @client.commit(user_project, event["commit_id"])
commit = commit.to_hash.stringify_keys_deep!
commit = stringify_keys_deep(commit.to_hash)
commit
end
end
private
def stringify_keys_deep(indata)
case indata
when Array
indata.map do |value|
stringify_keys_deep(value)
end
when Hash
indata.each_with_object({}) do |(k, v), output|
output[k.to_s] = stringify_keys_deep(v)
end
else
indata
end
end
# Iterates through all pages until there are no more :next pages to follow
# yields the result per page
#