From bcae8048092b122e7a3fd7d6e72bb8e79822d3cb Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Wed, 18 Feb 2015 01:24:51 +0200 Subject: [PATCH] Add filtering of Pull Requests by milestones --- lib/CHANGELOG.md | 6 ++- lib/github_changelog_generator.rb | 69 +++++++++++++++++-------------- 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index ca50b6e..82c4e60 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -3,6 +3,8 @@ ## [1.2.8](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.8) [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.7...1.2.8) #### 17/02/15 +- *Merged pull-request:* Feature/fix 37 [\#49](https://github.com/skywinder/Github-Changelog-Generator/pull/49) ([skywinder](https://github.com/skywinder)) + - *Closed issue:* Bugs, that closed simultaneously with push not appeared in correct version. [\#37](https://github.com/skywinder/Github-Changelog-Generator/issues/37) ## [1.2.7](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.7) @@ -29,8 +31,6 @@ ## [1.2.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.4) [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.3...1.2.4) #### 16/12/14 -- *Merged pull-request:* Fix crash when user is NULL [\#40](https://github.com/skywinder/Github-Changelog-Generator/pull/40) ([skywinder](https://github.com/skywinder)) - - *Merged pull-request:* Implement async fetching [\#39](https://github.com/skywinder/Github-Changelog-Generator/pull/39) ([skywinder](https://github.com/skywinder)) - *Fixed bug:* Crash when try generate log for rails [\#35](https://github.com/skywinder/Github-Changelog-Generator/issues/35) @@ -38,6 +38,8 @@ ## [1.2.3](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3) [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.2...1.2.3) #### 16/12/14 +- *Merged pull-request:* Fix crash when user is NULL [\#40](https://github.com/skywinder/Github-Changelog-Generator/pull/40) ([skywinder](https://github.com/skywinder)) + - *Implemented enhancement:* Add ability to run with one parameter instead -u -p [\#38](https://github.com/skywinder/Github-Changelog-Generator/issues/38) - *Implemented enhancement:* Detailed output [\#33](https://github.com/skywinder/Github-Changelog-Generator/issues/33) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 49d611b..18f7d95 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -293,44 +293,49 @@ module GitHubChangelogGenerator 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? - false - else - issue.milestone.title == newer_tag_name - end - end - } - - filtered_issues |= issues_to_add + filtered_issues = filter_by_milestone(filtered_issues, newer_tag_name, @issues) + filtered_pull_requests = filter_by_milestone(filtered_pull_requests, newer_tag_name, @pull_requests) end self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time, older_tag_name) end + def filter_by_milestone(filtered_issues, newer_tag_name, src_array) + 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 = src_array.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 + end + def delete_by_time(array, hash_key, newer_tag_time, older_tag = nil) older_tag_time = self.get_time_of_tag(older_tag)