Add ability to add ot exclude issues wothout any labels

This commit is contained in:
Petr Korolev 2014-11-10 15:32:06 +02:00
parent fc96007741
commit f08685b015
2 changed files with 21 additions and 8 deletions

View File

@ -85,7 +85,7 @@ class ChangelogGenerator
puts log
end
log += "\n\n* *This changelog was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
log += "\n\n\\* *This changelog was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
output_filename = "#{@options[:output]}"
File.open(output_filename, 'w') { |file| file.write(log) }
@ -286,15 +286,25 @@ class ChangelogGenerator
def get_all_issues
all_issues = []
@options[:labels].each { |label|
issues = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: label
all_issues = all_issues.concat(issues.body)
issues_req = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
filtered_issues = issues_req.body.select { |issues|
(issues.labels.map { |issue| issue.name} & @options[:labels]).any?
}
if @options[:add_issues_wo_labels]
issues_wo_labels = issues_req.body.select {
|issues| !issues.labels.map { |issue| issue.name}.any?
}
filtered_issues.concat(issues_wo_labels)
end
if @options[:verbose]
puts "Receive all closed issues with labels #{@options[:labels]}: #{all_issues.count} issues"
end
all_issues
filtered_issues
end

View File

@ -3,7 +3,7 @@ require 'optparse'
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}
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 }
parser = OptionParser.new { |opts|
opts.banner = 'Usage: changelog_generator [options]'
@ -20,12 +20,15 @@ class Parser
puts opts
exit
end
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
opts.on('-v', '--[no-]verbose', 'Run verbosely. Default is true') do |v|
options[:verbose] = v
end
opts.on('--[no-]issues', 'Include closed issues to changelog. Default is true') do |v|
options[:issues] = v
end
opts.on('--[no-]issues-without-labels', 'Include closed issues without any labels to changelog. Default is true') do |v|
options[:add_issues_wo_labels] = v
end
opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v|
options[:pulls] = v
end