From 643f2f9eabc69b672f57eda856b5c4ae5d82a311 Mon Sep 17 00:00:00 2001 From: Shawn Neal Date: Fri, 20 Mar 2015 18:41:15 -0700 Subject: [PATCH] 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. --- README.md | 1 + lib/github_changelog_generator.rb | 1 + lib/github_changelog_generator/parser.rb | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/README.md b/README.md index ccc650a..a97042c 100644 --- a/README.md +++ b/README.md @@ -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 --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' + --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-api [URL] The enterprise endpoint to use for your Github API. -v, --version Print version number diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 3e51717..03fcdb2 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -596,6 +596,7 @@ begin page_i += PER_PAGE_NUMBER print "Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\r" issues.concat(page) + break if issues.length >= @options[:max_issues] end rescue puts "Warning: GitHub API rate limit exceed (5000 per hour), change log may not contain some issues.".yellow diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index b23eead..f86d4c3 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -24,6 +24,7 @@ module GitHubChangelogGenerator :enhancement_prefix => '**Implemented enhancements:**', :author => true, :filter_issues_by_milestone => true, + :max_issues => 500, :compare_link => true, :unreleased => true, :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| options[:exclude_labels] = list 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| options[:github_site] = last end