OctoFetcher: Use defaults for request_options (#571)

* OctoFetcher: rely on default args

  - in iterate_pages

* OctoFetcher: extract options method
This commit is contained in:
Olle Jonsson 2017-10-10 23:48:00 +02:00 committed by GitHub
parent 23b341f715
commit 3f8fb60af3

View File

@ -108,7 +108,7 @@ module GitHubChangelogGenerator
page_i = 0 page_i = 0
count_pages = calculate_pages(@client, "tags", {}) count_pages = calculate_pages(@client, "tags", {})
iterate_pages(@client, "tags", {}) do |new_tags| iterate_pages(@client, "tags") do |new_tags|
page_i += PER_PAGE_NUMBER page_i += PER_PAGE_NUMBER
print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}") print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
tags.concat(new_tags) tags.concat(new_tags)
@ -125,6 +125,12 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
tags.map { |resource| stringify_keys_deep(resource.to_hash) } tags.map { |resource| stringify_keys_deep(resource.to_hash) }
end end
def closed_pr_options
@closed_pr_options ||= {
filter: "all", labels: nil, state: "closed"
}.tap { |options| options[:since] = @since if @since }
end
# This method fetch all closed issues and separate them to pull requests and pure issues # This method fetch all closed issues and separate them to pull requests and pure issues
# (pull request is kind of issue in term of GitHub) # (pull request is kind of issue in term of GitHub)
# #
@ -132,17 +138,10 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
def fetch_closed_issues_and_pr def fetch_closed_issues_and_pr
print "Fetching closed issues...\r" if @options[:verbose] print "Fetching closed issues...\r" if @options[:verbose]
issues = [] issues = []
options = {
state: "closed",
filter: "all",
labels: nil
}
options[:since] = @since unless @since.nil?
page_i = 0 page_i = 0
count_pages = calculate_pages(@client, "issues", options) count_pages = calculate_pages(@client, "issues", closed_pr_options)
iterate_pages(@client, "issues", options) do |new_issues| iterate_pages(@client, "issues", closed_pr_options) do |new_issues|
page_i += PER_PAGE_NUMBER page_i += PER_PAGE_NUMBER
print_in_same_line("Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}") print_in_same_line("Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
issues.concat(new_issues) issues.concat(new_issues)
@ -194,7 +193,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
issues_slice.each do |issue| issues_slice.each do |issue|
threads << Thread.new do threads << Thread.new do
issue["events"] = [] issue["events"] = []
iterate_pages(@client, "issue_events", issue["number"], {}) do |new_event| iterate_pages(@client, "issue_events", issue["number"]) do |new_event|
issue["events"].concat(new_event) issue["events"].concat(new_event)
end end
issue["events"] = issue["events"].map { |event| stringify_keys_deep(event.to_hash) } issue["events"] = issue["events"].map { |event| stringify_keys_deep(event.to_hash) }