From e6bb72835508664883bee543959e4beec0aaf58f Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 22 Dec 2014 15:14:01 +0200 Subject: [PATCH 1/4] remove issues with other milstones --- lib/github_changelog_generator.rb | 25 ++++++++++++++++++++- lib/github_changelog_generator/generator.rb | 6 ++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 9e37a75..718438c 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -243,6 +243,29 @@ module GitHubChangelogGenerator filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time) end + + #delete excess irrelevant issues (according milestones) + filtered_issues.select!{ |issue| + if issue.milestone.nil? + true + else + #check, that this milestone in tag list: + milestone_is_tag = @all_tags.find{|tag| + tag.name == issue.milestone.title + } + + if milestone_is_tag.nil? + true + else + issue.milestone.title == newer_tag_name + end + end + + } + + #add missed issues (according milestones) + + self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time) end @@ -395,7 +418,7 @@ module GitHubChangelogGenerator if @options[:add_issues_wo_labels] issues_wo_labels = issues.select { # add issues without any labels - |issue| !issue.labels.map { |label| label.name }.any? + |issue| !issue.labels.map { |label| label.name }.any? } filtered_issues.concat(issues_wo_labels) end diff --git a/lib/github_changelog_generator/generator.rb b/lib/github_changelog_generator/generator.rb index 5680f41..0c08a3d 100644 --- a/lib/github_changelog_generator/generator.rb +++ b/lib/github_changelog_generator/generator.rb @@ -10,10 +10,10 @@ module GitHubChangelogGenerator merge = "#{@options[:merge_prefix]}#{encapsulated_title} [\\##{pull_request[:number]}](#{pull_request.html_url})" if @options[:author] - if !pull_request.user.nil? - merge += " ([#{pull_request.user.login}](#{pull_request.user.html_url}))\n\n" - else + if pull_request.user.nil? merge += " ({Null user})\n\n" + else + merge += " ([#{pull_request.user.login}](#{pull_request.user.html_url}))\n\n" end else merge += "\n\n" From 5304e4faf85c87d1cf614ab3ef590cf511a4c95c Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 22 Dec 2014 15:31:49 +0200 Subject: [PATCH 2/4] fix #22 --- CHANGELOG.md | 10 ++++++---- lib/github_changelog_generator.rb | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ab6a16..5270bc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,20 +12,24 @@ - *Fixed bug:* Docs lacking or basic behavior not as advertised [\#30](https://github.com/skywinder/Github-Changelog-Generator/issues/30) +- *Fixed bug:* Crash when try generate log for rails [\#35](https://github.com/skywinder/Github-Changelog-Generator/issues/35) + ## [1.2.3] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3) #### 16/12/14 -- *Fixed bug:* Encapsulate \[ \> \* \_ \ \] signs in issues names [\#34](https://github.com/skywinder/Github-Changelog-Generator/issues/34) - ## [1.2.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.2) #### 10/12/14 - *Merged pull-request:* Add a Bitdeli Badge to README [\#36](https://github.com/skywinder/Github-Changelog-Generator/pull/36) ([bitdeli-chef](https://github.com/bitdeli-chef)) +- *Fixed bug:* Encapsulate \[ \> \* \_ \ \] signs in issues names [\#34](https://github.com/skywinder/Github-Changelog-Generator/issues/34) + ## [1.2.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.1) #### 22/11/14 - *Merged pull-request:* Issues for last tag not in list [\#29](https://github.com/skywinder/Github-Changelog-Generator/pull/29) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Disable default --filter-pull-requests option. [\#28](https://github.com/skywinder/Github-Changelog-Generator/pull/28) ([skywinder](https://github.com/skywinder)) +- *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20) + ## [1.2.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.0) #### 19/11/14 - *Merged pull-request:* Add filter for pull-requests labels. \(option --filter-pull-requests\) [\#27](https://github.com/skywinder/Github-Changelog-Generator/pull/27) ([skywinder](https://github.com/skywinder)) @@ -42,8 +46,6 @@ - *Implemented enhancement:* Implement ability to retrieve GitHub token from ENV variable \(to not put it to script directly\) [\#19](https://github.com/skywinder/Github-Changelog-Generator/issues/19) -- *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20) - ## [1.1.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.2) #### 12/11/14 - *Merged pull-request:* Fix bug with dot signs in project name [\#18](https://github.com/skywinder/Github-Changelog-Generator/pull/18) ([skywinder](https://github.com/skywinder)) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 718438c..27e8688 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -253,18 +253,30 @@ module GitHubChangelogGenerator milestone_is_tag = @all_tags.find{|tag| tag.name == issue.milestone.title } - - if milestone_is_tag.nil? - true - else - issue.milestone.title == newer_tag_name - end + milestone_is_tag.nil? end } #add missed issues (according milestones) + issues_to_add = @issues.select{|issue| + if issue.milestone.nil? + false + else + #check, that this milestone in tag list: + milestone_is_tag = @all_tags.find{|tag| + tag.name == issue.milestone.title + } + if milestone_is_tag.nil? + false + else + issue.milestone.title == newer_tag_name + end + end + } + + filtered_issues |= issues_to_add self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time) From 657ce0e83842aa6e0533edc0ef15a7977776abe7 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 22 Dec 2014 15:41:20 +0200 Subject: [PATCH 3/4] add ability to disable milestones filtering --- CHANGELOG.md | 10 ++-- lib/github_changelog_generator.rb | 60 ++++++++++++------------ lib/github_changelog_generator/parser.rb | 5 +- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5270bc3..7ab6a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,24 +12,20 @@ - *Fixed bug:* Docs lacking or basic behavior not as advertised [\#30](https://github.com/skywinder/Github-Changelog-Generator/issues/30) -- *Fixed bug:* Crash when try generate log for rails [\#35](https://github.com/skywinder/Github-Changelog-Generator/issues/35) - ## [1.2.3] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3) #### 16/12/14 +- *Fixed bug:* Encapsulate \[ \> \* \_ \ \] signs in issues names [\#34](https://github.com/skywinder/Github-Changelog-Generator/issues/34) + ## [1.2.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.2) #### 10/12/14 - *Merged pull-request:* Add a Bitdeli Badge to README [\#36](https://github.com/skywinder/Github-Changelog-Generator/pull/36) ([bitdeli-chef](https://github.com/bitdeli-chef)) -- *Fixed bug:* Encapsulate \[ \> \* \_ \ \] signs in issues names [\#34](https://github.com/skywinder/Github-Changelog-Generator/issues/34) - ## [1.2.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.1) #### 22/11/14 - *Merged pull-request:* Issues for last tag not in list [\#29](https://github.com/skywinder/Github-Changelog-Generator/pull/29) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Disable default --filter-pull-requests option. [\#28](https://github.com/skywinder/Github-Changelog-Generator/pull/28) ([skywinder](https://github.com/skywinder)) -- *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20) - ## [1.2.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.0) #### 19/11/14 - *Merged pull-request:* Add filter for pull-requests labels. \(option --filter-pull-requests\) [\#27](https://github.com/skywinder/Github-Changelog-Generator/pull/27) ([skywinder](https://github.com/skywinder)) @@ -46,6 +42,8 @@ - *Implemented enhancement:* Implement ability to retrieve GitHub token from ENV variable \(to not put it to script directly\) [\#19](https://github.com/skywinder/Github-Changelog-Generator/issues/19) +- *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20) + ## [1.1.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.2) #### 12/11/14 - *Merged pull-request:* Fix bug with dot signs in project name [\#18](https://github.com/skywinder/Github-Changelog-Generator/pull/18) ([skywinder](https://github.com/skywinder)) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 27e8688..60a2982 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -244,39 +244,41 @@ module GitHubChangelogGenerator end - #delete excess irrelevant issues (according milestones) - filtered_issues.select!{ |issue| - if issue.milestone.nil? - true - else - #check, that this milestone in tag list: - milestone_is_tag = @all_tags.find{|tag| - tag.name == issue.milestone.title - } - milestone_is_tag.nil? - end + if @options[:filter_issues_by_milestone] + #delete excess irrelevant issues (according milestones) + filtered_issues.select! { |issue| + if issue.milestone.nil? + true + else + #check, that this milestone in tag list: + milestone_is_tag = @all_tags.find { |tag| + tag.name == issue.milestone.title + } + milestone_is_tag.nil? + end - } + } - #add missed issues (according milestones) - issues_to_add = @issues.select{|issue| - if issue.milestone.nil? - false - else - #check, that this milestone in tag list: - milestone_is_tag = @all_tags.find{|tag| - tag.name == issue.milestone.title - } - - if milestone_is_tag.nil? + #add missed issues (according milestones) + issues_to_add = @issues.select { |issue| + if issue.milestone.nil? false else - issue.milestone.title == newer_tag_name - end - end - } + #check, that this milestone in tag list: + milestone_is_tag = @all_tags.find { |tag| + tag.name == issue.milestone.title + } - filtered_issues |= issues_to_add + if milestone_is_tag.nil? + false + else + issue.milestone.title == newer_tag_name + end + end + } + + filtered_issues |= issues_to_add + end self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time) @@ -430,7 +432,7 @@ module GitHubChangelogGenerator if @options[:add_issues_wo_labels] issues_wo_labels = issues.select { # add issues without any labels - |issue| !issue.labels.map { |label| label.name }.any? + |issue| !issue.labels.map { |label| label.name }.any? } filtered_issues.concat(issues_wo_labels) end diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 3ab11cc..c5a8fca 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, :pull_request_labels => nil} + 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 => nil, :filter_issues_by_milestone => true} parser = OptionParser.new { |opts| opts.banner = 'Usage: changelog_generator [options]' @@ -37,6 +37,9 @@ module GitHubChangelogGenerator opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v| options[:pulls] = v end + opts.on('--[no-]filter-issues-by-milestone', 'Use milestone to detect when issue was resolved. Default is true') do |last| + options[:filter_issues_by_milestone] = last + end opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author| options[:last] = author end From 6da115c4b0ebab34653be90b4a4d50a2b50c3b55 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 22 Dec 2014 15:51:45 +0200 Subject: [PATCH 4/4] Fix #32 --- lib/github_changelog_generator.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 60a2982..646c20f 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -231,6 +231,11 @@ module GitHubChangelogGenerator def generate_log_between_tags(older_tag, newer_tag) + if newer_tag.nil? + puts "Can't find tag -> terminate" + exit 1 + end + newer_tag_time = self.get_time_of_tag(newer_tag) newer_tag_name = newer_tag['name']