add parse option --filter-pull-requests
This commit is contained in:
parent
bdc4657e2c
commit
97311bc5a0
|
@ -61,19 +61,36 @@ module GitHubChangelogGenerator
|
||||||
puts "Received all closed pull requests: #{pull_requests.count}"
|
puts "Received all closed pull requests: #{pull_requests.count}"
|
||||||
end
|
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|
|
filtered_pull_requests = pull_requests.select { |pull_request|
|
||||||
#We need issue to fetch labels
|
#We need issue to fetch labels
|
||||||
issue = @github.issues.get @options[:user], @options[:project], pull_request.number
|
issue = @github.issues.get @options[:user], @options[:project], pull_request.number
|
||||||
#compare is there any labels from @options[:labels] array
|
#compare is there any labels from @options[:labels] array
|
||||||
select_no_label = !issue.labels.map { |label| label.name }.any?
|
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
|
select_by_label | select_no_label
|
||||||
}
|
}
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts "Filtered pull requests with specified labels and w/o labels: #{filtered_pull_requests.count}"
|
puts "Filtered pull requests with specified labels and w/o labels: #{filtered_pull_requests.count}"
|
||||||
end
|
end
|
||||||
|
return filtered_pull_requests
|
||||||
|
end
|
||||||
pull_requests
|
pull_requests
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -191,12 +208,12 @@ module GitHubChangelogGenerator
|
||||||
newer_tag_name = newer_tag['name']
|
newer_tag_name = newer_tag['name']
|
||||||
|
|
||||||
if older_tag.nil?
|
if older_tag.nil?
|
||||||
filtered_pull_requests = delete_by_time(@pull_requests ,:merged_at, newer_tag_time)
|
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time)
|
||||||
issues = delete_by_time(@issues ,:closed_at, newer_tag_time)
|
issues = delete_by_time(@issues, :closed_at, newer_tag_time)
|
||||||
else
|
else
|
||||||
older_tag_time = self.get_time_of_tag(older_tag)
|
older_tag_time = self.get_time_of_tag(older_tag)
|
||||||
filtered_pull_requests = delete_by_time(@pull_requests ,:merged_at, newer_tag_time, older_tag_time)
|
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag_time)
|
||||||
issues = delete_by_time(@issues ,:closed_at, newer_tag_time, older_tag_time)
|
issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.create_log(filtered_pull_requests, issues, newer_tag_name, newer_tag_time)
|
self.create_log(filtered_pull_requests, issues, newer_tag_name, newer_tag_time)
|
||||||
|
|
|
@ -6,7 +6,7 @@ require_relative 'version'
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
class Parser
|
class Parser
|
||||||
def self.parse_options
|
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|
|
parser = OptionParser.new { |opts|
|
||||||
opts.banner = 'Usage: changelog_generator [options]'
|
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|
|
opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last|
|
||||||
options[:output] = last
|
options[:output] = last
|
||||||
end
|
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
|
options[:labels] = list
|
||||||
end
|
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|
|
opts.on('-v', '--version', 'Print version number') do |v|
|
||||||
puts "Version: #{GitHubChangelogGenerator::VERSION}"
|
puts "Version: #{GitHubChangelogGenerator::VERSION}"
|
||||||
exit
|
exit
|
||||||
|
|
Loading…
Reference in New Issue
Block a user