Add --max-issues argument to limit requests

This addresses issue 71 by providing a configurable limit on the number of issues to retrieve. By default this limits the number of issues to 500 which should help users stay under the GitHub API limit and keep change logs from growing ridiculous in size for older repos.
This commit is contained in:
Shawn Neal 2015-03-20 18:41:15 -07:00 committed by Petr Korolev
parent d43ef05287
commit 90f6436af6
3 changed files with 6 additions and 0 deletions

View File

@ -96,6 +96,7 @@ Type `github_changelog_generator --help` for detailed usage.
--[no-]compare-link Include compare link between older version and newer version. Default is true --[no-]compare-link Include compare link between older version and newer version. Default is true
--include-labels x,y,z Issues only with that labels will be included to changelog. Default is 'bug,enhancement' --include-labels x,y,z Issues only with that labels will be included to changelog. Default is 'bug,enhancement'
--exclude-labels x,y,z Issues with that labels will be always excluded from changelog. Default is 'duplicate,question,invalid,wontfix' --exclude-labels x,y,z Issues with that labels will be always excluded from changelog. Default is 'duplicate,question,invalid,wontfix'
--max-issues [NUMBER] Max number of issues to fetch from GitHub. Default is 500.
--github-site [URL] The Enterprise Github site on which your project is hosted. --github-site [URL] The Enterprise Github site on which your project is hosted.
--github-api [URL] The enterprise endpoint to use for your Github API. --github-api [URL] The enterprise endpoint to use for your Github API.
-v, --version Print version number -v, --version Print version number

View File

@ -596,6 +596,7 @@ begin
page_i += PER_PAGE_NUMBER page_i += PER_PAGE_NUMBER
print "Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\r" print "Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\r"
issues.concat(page) issues.concat(page)
break if issues.length >= @options[:max_issues]
end end
rescue rescue
puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow

View File

@ -24,6 +24,7 @@ module GitHubChangelogGenerator
:enhancement_prefix => '**Implemented enhancements:**', :enhancement_prefix => '**Implemented enhancements:**',
:author => true, :author => true,
:filter_issues_by_milestone => true, :filter_issues_by_milestone => true,
:max_issues => 500,
:compare_link => true, :compare_link => true,
:unreleased => true, :unreleased => true,
:unreleased_label => 'Unreleased', :unreleased_label => 'Unreleased',
@ -83,6 +84,9 @@ module GitHubChangelogGenerator
opts.on('--exclude-labels x,y,z', Array, 'Issues with that labels will be always excluded from changelog. Default is \'duplicate,question,invalid,wontfix\'') do |list| opts.on('--exclude-labels x,y,z', Array, 'Issues with that labels will be always excluded from changelog. Default is \'duplicate,question,invalid,wontfix\'') do |list|
options[:exclude_labels] = list options[:exclude_labels] = list
end end
opts.on('--max-issues [NUMBER]', Integer, 'Max number of issues to fetch from GitHub. Default is 500') do |max|
options[:max_issues] = max
end
opts.on('--github-site [URL]', 'The Enterprise Github site on which your project is hosted.') do |last| opts.on('--github-site [URL]', 'The Enterprise Github site on which your project is hosted.') do |last|
options[:github_site] = last options[:github_site] = last
end end