From 0c8a96aef81fc58dc542dc9a1534b7c6ae3c850d Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Wed, 19 Nov 2014 14:33:38 +0200 Subject: [PATCH 1/3] update readme --- README.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2ffd38d..9bf5266 100644 --- a/README.md +++ b/README.md @@ -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. 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 - -h, --help Displays Help - -v, --[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 - -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' + -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 here: https://github.com/settings/tokens/new + -h, --help Displays Help + --[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: From bdc4657e2c62fbd4180b952d166afd8e67603911 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Wed, 19 Nov 2014 14:56:08 +0200 Subject: [PATCH 2/3] add filter option --- lib/github_changelog_generator.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 4f7632c..9200457 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -61,6 +61,19 @@ module GitHubChangelogGenerator puts "Received all closed pull requests: #{pull_requests.count}" 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? + 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 + pull_requests end From 97311bc5a07fe061f9d16438b7d71d42ab811eb0 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Wed, 19 Nov 2014 15:45:24 +0200 Subject: [PATCH 3/3] add parse option --filter-pull-requests --- lib/github_changelog_generator.rb | 47 ++++++++++++++++-------- lib/github_changelog_generator/parser.rb | 7 +++- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 9200457..b2a226a 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -61,19 +61,36 @@ module GitHubChangelogGenerator puts "Received all closed pull requests: #{pull_requests.count}" 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? - select_by_label | select_no_label - } + unless @options[:pull_request_labels].nil? - if @options[:verbose] - puts "Filtered pull requests with specified labels and w/o labels: #{filtered_pull_requests.count}" + 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 @@ -191,12 +208,12 @@ module GitHubChangelogGenerator newer_tag_name = newer_tag['name'] if older_tag.nil? - filtered_pull_requests = delete_by_time(@pull_requests ,:merged_at, newer_tag_time) - issues = delete_by_time(@issues ,:closed_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) else 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) - issues = delete_by_time(@issues ,:closed_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) end self.create_log(filtered_pull_requests, issues, newer_tag_name, newer_tag_time) diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index adc202c..69a4080 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -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