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

@ -27,18 +27,20 @@ As output you will get `CHANGELOG.md` file with *pretty Markdown-formatted* chan
Type `github_changelog_generator --help` for detailed usage. Type `github_changelog_generator --help` for detailed usage.
Usage: changelog_generator [options] Usage: changelog_generator [options]
-u, --user [USER] Username of the owner of target GitHub repo -u, --user [USER] Username of the owner of target GitHub repo
-p, --project [PROJECT] Name of project on GitHub -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 -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 Include closed issues to changelog. Default is true
--[no-]issues-without-labels Include closed issues without any labels 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 --[no-]pull-requests Include pull-requests to changelog. Default is true
-l, --last-changes Generate log between last 2 tags only -l, --last-changes Generate log between last 2 tags only
-f, --date-format [FORMAT] Date format. Default is %d/%m/%y --[no-]author Add author of pull-request in the end. Default is true
-o, --output [NAME] Output file. Default is CHANGELOG.md -f, --date-format [FORMAT] Date format. Default is %d/%m/%y
--labels x,y,z List of labels. Issues with that labels will be included to changelog. Default is 'bug,enhancement' -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: ## Examples:

View File

@ -61,6 +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|
#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 pull_requests
end end
@ -178,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)

View File

@ -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