From 40dec5346b46fb96a4078910ddea300714e0b091 Mon Sep 17 00:00:00 2001 From: soundstep Date: Fri, 22 Jan 2016 13:32:31 +0000 Subject: [PATCH 01/11] filter-tags - Added capability to exclude tags with a regular expression by filtering names. --- lib/github_changelog_generator/fetcher.rb | 14 ++++++++++++++ lib/github_changelog_generator/parser.rb | 3 +++ 2 files changed, 17 insertions(+) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index eef3e6d..1a6d61c 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -68,11 +68,25 @@ module GitHubChangelogGenerator response = @github.repos.tags @options[:user], @options[:project] page_i = 0 count_pages = response.count_pages + response.each_page do |page| + + if @options[:filter_tags] + body_new = [] + reg = Regexp.new @options[:filter_tags] + page.body.each_with_index do |tag,index| + if !(tag.name =~ reg) + body_new << tag + end + end + page.body = body_new + end + page_i += PER_PAGE_NUMBER print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}") tags.concat(page) end + print_empty_line if tags.count == 0 diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 2f16d9b..4c79889 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -116,6 +116,9 @@ module GitHubChangelogGenerator opts.on("--between-tags x,y,z", Array, "Change log will be filled only between specified tags") do |list| options[:between_tags] = list end + opts.on("--filter-tags [REGEX]", "Apply a regular expression on tag names so that they can be excluded, for example: --filter-tags \".*\+\d{1,}\" ") do |last| + options[:filter_tags] = last + end opts.on("--exclude-tags x,y,z", Array, "Change log will exclude specified tags") do |list| options[:exclude_tags] = list end From a676650993ee1d32ae7da9ce8c5bf57544e35f8d Mon Sep 17 00:00:00 2001 From: soundstep Date: Fri, 22 Jan 2016 13:34:24 +0000 Subject: [PATCH 02/11] filter-tags - Remove unused index. --- lib/github_changelog_generator/fetcher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index 1a6d61c..f0023bf 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -74,7 +74,7 @@ module GitHubChangelogGenerator if @options[:filter_tags] body_new = [] reg = Regexp.new @options[:filter_tags] - page.body.each_with_index do |tag,index| + page.body.each do |tag| if !(tag.name =~ reg) body_new << tag end From 1bae4ea204153bc92b8ad2e71282237eb34380a8 Mon Sep 17 00:00:00 2001 From: soundstep Date: Fri, 22 Jan 2016 15:11:12 +0000 Subject: [PATCH 03/11] filter-tags - Rename option. --- lib/github_changelog_generator/fetcher.rb | 4 ++-- lib/github_changelog_generator/parser.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index f0023bf..f908e1d 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -71,9 +71,9 @@ module GitHubChangelogGenerator response.each_page do |page| - if @options[:filter_tags] + if @options[:exclude_tags_filter] body_new = [] - reg = Regexp.new @options[:filter_tags] + reg = Regexp.new @options[:exclude_tags_filter] page.body.each do |tag| if !(tag.name =~ reg) body_new << tag diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 4c79889..034bb82 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -116,8 +116,8 @@ module GitHubChangelogGenerator opts.on("--between-tags x,y,z", Array, "Change log will be filled only between specified tags") do |list| options[:between_tags] = list end - opts.on("--filter-tags [REGEX]", "Apply a regular expression on tag names so that they can be excluded, for example: --filter-tags \".*\+\d{1,}\" ") do |last| - options[:filter_tags] = last + opts.on("--exclude-tags-filter [REGEX]", "Apply a regular expression on tag names so that they can be excluded, for example: --exclude-tags-filter \".*\+\d{1,}\" ") do |last| + options[:exclude_tags_filter] = last end opts.on("--exclude-tags x,y,z", Array, "Change log will exclude specified tags") do |list| options[:exclude_tags] = list From dd149d7ad94ddb7c28a995369f726a25ad91ed9c Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 24 Mar 2016 11:59:20 +0000 Subject: [PATCH 04/11] implement #filter_excluded_tags_regex with regex exclude_tags --- .../generator/generator_tags.rb | 23 +++++++++++++++---- spec/unit/generator/generator_tags_spec.rb | 10 ++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index 0966df1..3d01497 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -131,9 +131,13 @@ module GitHubChangelogGenerator # @param [Array] all_tags all tags # @return [Array] filtered tags according :exclude_tags option def filter_excluded_tags(all_tags) - return all_tags unless @options[:exclude_tags] - - apply_exclude_tags(all_tags) + if @options[:exclude_tags] + apply_exclude_tags(all_tags) + elsif @options[:exclude_tags_regex] + apply_exclude_tags_regex(all_tags) + else + all_tags + end end private @@ -146,9 +150,20 @@ module GitHubChangelogGenerator end end + def apply_exclude_tags_regex(all_tags) + filter_tags_with_regex(all_tags) + end + def filter_tags_with_regex(all_tags) warn_if_nonmatching_regex(all_tags) - all_tags.reject { |tag| @options[:exclude_tags] =~ tag.name } + + if @options[:exclude_tags] + all_tags.reject { |tag| @options[:exclude_tags] =~ tag.name } + elsif @options[:exclude_tags_regex] + regex = Regexp.new(@options[:exclude_tags_regex]) + all_tags.reject { |tag| regex =~ tag.name } + end + end def filter_exact_tags(all_tags) diff --git a/spec/unit/generator/generator_tags_spec.rb b/spec/unit/generator/generator_tags_spec.rb index a2a3dff..3a14e36 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -73,6 +73,16 @@ describe GitHubChangelogGenerator::Generator do end end + describe "#filter_excluded_tags_regex" do + subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(v1.2.3+12 v1.2.3))) } + + context "with regex exclude_tags" do + let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '.*\+\d{1,}') } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w(v1.2.3))) } + end + end + describe "#filter_excluded_tags" do subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) } From e5a619b167ae8c6c36361447ef83588685ff51b2 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 24 Mar 2016 12:06:39 +0000 Subject: [PATCH 05/11] add test for #filter_excluded_tags_regex with non-matching regex in exclude_tags --- spec/unit/generator/generator_tags_spec.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/unit/generator/generator_tags_spec.rb b/spec/unit/generator/generator_tags_spec.rb index 3a14e36..2dfeb8c 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -74,12 +74,18 @@ describe GitHubChangelogGenerator::Generator do end describe "#filter_excluded_tags_regex" do - subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(v1.2.3+12 v1.2.3))) } + subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) } context "with regex exclude_tags" do - let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '.*\+\d{1,}') } + let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '2') } it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_mash_from_strings(%w(v1.2.3))) } + it { is_expected.to match_array(tags_mash_from_strings(%w(1 3))) } + end + + context "with non-matching regex in exclude_tags" do + let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: 'invalid tags') } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } end end From 6a0ade1194dee6c495a90b319df23c3536fb40e2 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 24 Mar 2016 12:22:33 +0000 Subject: [PATCH 06/11] refactor --- lib/github_changelog_generator/fetcher.rb | 14 ------------ .../generator/generator_tags.rb | 22 +++++-------------- lib/github_changelog_generator/parser.rb | 6 ++--- 3 files changed, 8 insertions(+), 34 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index f908e1d..eef3e6d 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -68,25 +68,11 @@ module GitHubChangelogGenerator response = @github.repos.tags @options[:user], @options[:project] page_i = 0 count_pages = response.count_pages - response.each_page do |page| - - if @options[:exclude_tags_filter] - body_new = [] - reg = Regexp.new @options[:exclude_tags_filter] - page.body.each do |tag| - if !(tag.name =~ reg) - body_new << tag - end - end - page.body = body_new - end - page_i += PER_PAGE_NUMBER print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}") tags.concat(page) end - print_empty_line if tags.count == 0 diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index 3d01497..cbf8198 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -129,12 +129,12 @@ module GitHubChangelogGenerator end # @param [Array] all_tags all tags - # @return [Array] filtered tags according :exclude_tags option + # @return [Array] filtered tags according :exclude_tags or :exclude_tags_regex option def filter_excluded_tags(all_tags) - if @options[:exclude_tags] - apply_exclude_tags(all_tags) - elsif @options[:exclude_tags_regex] - apply_exclude_tags_regex(all_tags) + if (@options[:exclude_tags].is_a?(Regexp) || @options[:exclude_tags_regex]) + filter_tags_with_regex(all_tags) + elsif @options[:exclude_tags] + filter_exact_tags(all_tags) else all_tags end @@ -142,18 +142,6 @@ module GitHubChangelogGenerator private - def apply_exclude_tags(all_tags) - if @options[:exclude_tags].is_a?(Regexp) - filter_tags_with_regex(all_tags) - else - filter_exact_tags(all_tags) - end - end - - def apply_exclude_tags_regex(all_tags) - filter_tags_with_regex(all_tags) - end - def filter_tags_with_regex(all_tags) warn_if_nonmatching_regex(all_tags) diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 034bb82..97e5ed5 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -116,12 +116,12 @@ module GitHubChangelogGenerator opts.on("--between-tags x,y,z", Array, "Change log will be filled only between specified tags") do |list| options[:between_tags] = list end - opts.on("--exclude-tags-filter [REGEX]", "Apply a regular expression on tag names so that they can be excluded, for example: --exclude-tags-filter \".*\+\d{1,}\" ") do |last| - options[:exclude_tags_filter] = last - end opts.on("--exclude-tags x,y,z", Array, "Change log will exclude specified tags") do |list| options[:exclude_tags] = list end + opts.on("--exclude-tags-regex [REGEX]", "Apply a regular expression on tag names so that they can be excluded, for example: --exclude-tags-regex \".*\+\d{1,}\" ") do |last| + options[:exclude_tags_regex] = last + end opts.on("--since-tag x", "Change log will start after specified tag") do |v| options[:since_tag] = v end From 61ec6508010e8f5c26d4d4a391b6a4130615d56d Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 24 Mar 2016 12:40:42 +0000 Subject: [PATCH 07/11] refactor --- .../generator/generator_tags.rb | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index cbf8198..5d679df 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -131,10 +131,10 @@ module GitHubChangelogGenerator # @param [Array] all_tags all tags # @return [Array] filtered tags according :exclude_tags or :exclude_tags_regex option def filter_excluded_tags(all_tags) - if (@options[:exclude_tags].is_a?(Regexp) || @options[:exclude_tags_regex]) - filter_tags_with_regex(all_tags) - elsif @options[:exclude_tags] - filter_exact_tags(all_tags) + if @options[:exclude_tags] + apply_exclude_tags(all_tags) + elsif @options[:exclude_tags_regex] + apply_exclude_tags_regex(all_tags) else all_tags end @@ -142,16 +142,21 @@ module GitHubChangelogGenerator private - def filter_tags_with_regex(all_tags) - warn_if_nonmatching_regex(all_tags) - - if @options[:exclude_tags] - all_tags.reject { |tag| @options[:exclude_tags] =~ tag.name } - elsif @options[:exclude_tags_regex] - regex = Regexp.new(@options[:exclude_tags_regex]) - all_tags.reject { |tag| regex =~ tag.name } + def apply_exclude_tags(all_tags) + if @options[:exclude_tags].is_a?(Regexp) + filter_tags_with_regex(all_tags, @options[:exclude_tags]) + else + filter_exact_tags(all_tags) end + end + def apply_exclude_tags_regex(all_tags) + filter_tags_with_regex(all_tags, Regexp.new(@options[:exclude_tags_regex])) + end + + def filter_tags_with_regex(all_tags, regex) + warn_if_nonmatching_regex(all_tags) + all_tags.reject { |tag| regex =~ tag.name } end def filter_exact_tags(all_tags) From 17ceccdd70088e42548b9e336827b3e59089c7cd Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 24 Mar 2016 12:54:19 +0000 Subject: [PATCH 08/11] clean up test description --- spec/unit/generator/generator_tags_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/unit/generator/generator_tags_spec.rb b/spec/unit/generator/generator_tags_spec.rb index 2dfeb8c..54be1dd 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -76,13 +76,13 @@ describe GitHubChangelogGenerator::Generator do describe "#filter_excluded_tags_regex" do subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) } - context "with regex exclude_tags" do + context "with matching regex" do let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '2') } it { is_expected.to be_a Array } it { is_expected.to match_array(tags_mash_from_strings(%w(1 3))) } end - context "with non-matching regex in exclude_tags" do + context "with non-matching regex" do let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: 'invalid tags') } it { is_expected.to be_a Array } it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } @@ -92,25 +92,25 @@ describe GitHubChangelogGenerator::Generator do describe "#filter_excluded_tags" do subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) } - context "with valid excluded tags" do + context "with matching string" do let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags: %w(3)) } it { is_expected.to be_a Array } it { is_expected.to match_array(tags_mash_from_strings(%w(1 2))) } end - context "with invalid excluded tags" do + context "with non-matching string" do let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags: %w(invalid tags)) } it { is_expected.to be_a Array } it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } end - context "with regex exclude_tags" do + context "with matching regex" do let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags: /[23]/) } it { is_expected.to be_a Array } it { is_expected.to match_array(tags_mash_from_strings(%w(1))) } end - context "with non-matching regex in exclude_tags" do + context "with non-matching regex" do let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags: /[abc]/) } it { is_expected.to be_a Array } it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } From 21d41756b84bab7972af1030069b256cb1a168d8 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 24 Mar 2016 13:00:02 +0000 Subject: [PATCH 09/11] regex test include regex identifier --- spec/unit/generator/generator_tags_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/unit/generator/generator_tags_spec.rb b/spec/unit/generator/generator_tags_spec.rb index 54be1dd..0713551 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -77,13 +77,13 @@ describe GitHubChangelogGenerator::Generator do subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) } context "with matching regex" do - let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '2') } + let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '[23]') } it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_mash_from_strings(%w(1 3))) } + it { is_expected.to match_array(tags_mash_from_strings(%w(1))) } end context "with non-matching regex" do - let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: 'invalid tags') } + let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '[45]') } it { is_expected.to be_a Array } it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } end From 507ffdb91034cfd7c8c3e7ff6e4bff61467e2f4c Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 24 Mar 2016 13:00:53 +0000 Subject: [PATCH 10/11] put filter_excluded_tags_regex after filter_excluded_tags tests --- spec/unit/generator/generator_tags_spec.rb | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/unit/generator/generator_tags_spec.rb b/spec/unit/generator/generator_tags_spec.rb index 0713551..04c9b50 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -73,22 +73,6 @@ describe GitHubChangelogGenerator::Generator do end end - describe "#filter_excluded_tags_regex" do - subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) } - - context "with matching regex" do - let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '[23]') } - it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_mash_from_strings(%w(1))) } - end - - context "with non-matching regex" do - let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '[45]') } - it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } - end - end - describe "#filter_excluded_tags" do subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) } @@ -117,6 +101,22 @@ describe GitHubChangelogGenerator::Generator do end end + describe "#filter_excluded_tags_regex" do + subject { generator.filter_excluded_tags(tags_mash_from_strings(%w(1 2 3))) } + + context "with matching regex" do + let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '[23]') } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w(1))) } + end + + context "with non-matching regex" do + let(:generator) { GitHubChangelogGenerator::Generator.new(exclude_tags_regex: '[45]') } + it { is_expected.to be_a Array } + it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) } + end + end + describe "#filter_since_tag" do context "with filled array" do subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) } From 663d4d8c810c2dec8e8059279325dfc880f8e41e Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 1 Apr 2016 13:33:19 +0300 Subject: [PATCH 11/11] Update changelog for version 1.12.0 --- CHANGELOG.md | 12 ++++++++++++ Gemfile.lock | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc9093a..be8c8ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Change Log +## [1.12.0](https://github.com/skywinder/github-changelog-generator/tree/1.12.0) (2016-04-01) +[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/1.11.8...1.12.0) + +**Closed issues:** + +- .github\_changelog\_generator config file is not consistent with the internal options hash [\#312](https://github.com/skywinder/github-changelog-generator/issues/312) +- Feature request: YAML front matter [\#276](https://github.com/skywinder/github-changelog-generator/issues/276) + +**Merged pull requests:** + +- Added tag exclusion with a filter \(string or regex\) [\#320](https://github.com/skywinder/github-changelog-generator/pull/320) ([soundstep](https://github.com/soundstep)) + ## [1.11.8](https://github.com/skywinder/github-changelog-generator/tree/1.11.8) (2016-03-22) [Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/1.11.7...1.11.8) diff --git a/Gemfile.lock b/Gemfile.lock index 9f23236..fe0b9e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - github_changelog_generator (1.11.8) + github_changelog_generator (1.12.0) bundler (>= 1.7) colorize (~> 0.7) github_api (~> 0.12)