Merge branch 'filter-pull-requests'

This commit is contained in:
Petr Korolev 2014-11-19 15:47:28 +02:00
commit 3b145bd7ed
3 changed files with 53 additions and 18 deletions

View File

@ -29,16 +29,18 @@ Type `github_changelog_generator --help` for detailed usage.
Usage: changelog_generator [options]
-u, --user [USER] Username of the owner of target GitHub repo
-p, --project [PROJECT] Name of project on GitHub
-t, --token [TOKEN] To make more than 50 requests this script required your OAuth token for GitHub. You can generate it on https://github.com/settings/applications
-t, --token [TOKEN] To make more than 50 requests this script required your OAuth token for GitHub. You can generate here: https://github.com/settings/tokens/new
-h, --help Displays Help
-v, --[no-]verbose Run verbosely. Default is true
--[no-]verbose Run verbosely. Default is true
--[no-]issues Include closed issues to changelog. Default is true
--[no-]issues-without-labels Include closed issues without any labels to changelog. Default is true
--[no-]pull-requests Include pull-requests to changelog. Default is true
-l, --last-changes Generate log between last 2 tags only
--[no-]author Add author of pull-request in the end. Default is true
-f, --date-format [FORMAT] Date format. Default is %d/%m/%y
-o, --output [NAME] Output file. Default is CHANGELOG.md
--labels x,y,z List of labels. Issues with that labels will be included to changelog. Default is 'bug,enhancement'
-v, --version Print version number
## Examples:

View File

@ -61,6 +61,36 @@ module GitHubChangelogGenerator
puts "Received all closed pull requests: #{pull_requests.count}"
end
unless @options[:pull_request_labels].nil?
if @options[:verbose]
puts 'Filter all pull requests by labels.'
end
filtered_pull_requests = pull_requests.select { |pull_request|
#We need issue to fetch labels
issue = @github.issues.get @options[:user], @options[:project], pull_request.number
#compare is there any labels from @options[:labels] array
select_no_label = !issue.labels.map { |label| label.name }.any?
if @options[:verbose]
puts "Filter request \##{issue.number}."
end
if @options[:pull_request_labels].any?
select_by_label = (issue.labels.map { |label| label.name } & @options[:pull_request_labels]).any?
else
select_by_label = false
end
select_by_label | select_no_label
}
if @options[:verbose]
puts "Filtered pull requests with specified labels and w/o labels: #{filtered_pull_requests.count}"
end
return filtered_pull_requests
end
pull_requests
end

View File

@ -6,7 +6,7 @@ require_relative 'version'
module GitHubChangelogGenerator
class Parser
def self.parse_options
options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true, :verbose => true, :add_issues_wo_labels => true, :merge_prefix => '*Merged pull-request:* ', :author => true}
options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true, :verbose => true, :add_issues_wo_labels => true, :merge_prefix => '*Merged pull-request:* ', :author => true, :pull_request_labels => %w(bug enhancement)}
parser = OptionParser.new { |opts|
opts.banner = 'Usage: changelog_generator [options]'
@ -47,9 +47,12 @@ module GitHubChangelogGenerator
opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last|
options[:output] = last
end
opts.on('--labels x,y,z', Array, 'List of labels. Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
opts.on('--labels x,y,z', Array, 'Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
options[:labels] = list
end
opts.on('--filter-pull-requests x,y,z', Array, 'Pull requests with that labels will be included to changelog. pull requests w\o labels will be included anyway. Default is \'bug,enhancement\'') do |list|
options[:pull_request_labels] = list
end
opts.on('-v', '--version', 'Print version number') do |v|
puts "Version: #{GitHubChangelogGenerator::VERSION}"
exit