add parse option --filter-pull-requests

This commit is contained in:
Petr Korolev 2014-11-19 15:45:24 +02:00
parent bdc4657e2c
commit 97311bc5a0
2 changed files with 37 additions and 17 deletions

View File

@ -61,19 +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?
select_by_label = (issue.labels.map { |label| label.name } & @options[:labels]).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