diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index 9e4cc68..e300907 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -1,24 +1,24 @@ # Changelog -## [1.2.8](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.8) (2015-02-17) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.7...1.2.8) +## [1.2.8](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.8) - 17/02/15 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.7...1.2.8) - *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) (2015-01-26) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.6...1.2.7) +## [1.2.7](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.7) - 26/01/15 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.6...1.2.7) - *Merged pull-request:* Add compare link between older version and newer version [\#46](https://github.com/skywinder/Github-Changelog-Generator/pull/46) ([sue445](https://github.com/sue445)) -## [1.2.6](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.6) (2015-01-21) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.5...1.2.6) +## [1.2.6](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.6) - 21/01/15 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.5...1.2.6) - *Merged pull-request:* fix link tag format [\#45](https://github.com/skywinder/Github-Changelog-Generator/pull/45) ([sugamasao](https://github.com/sugamasao)) -## [1.2.5](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.5) (2015-01-15) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.4...1.2.5) +## [1.2.5](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.5) - 15/01/15 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.4...1.2.5) - *Merged pull-request:* PrettyPrint class is included using lowercase 'pp' [\#43](https://github.com/skywinder/Github-Changelog-Generator/pull/43) ([schwing](https://github.com/schwing)) @@ -28,8 +28,8 @@ - *Fixed bug:* Error when trying to generate log for repo without tags [\#32](https://github.com/skywinder/Github-Changelog-Generator/issues/32) -## [1.2.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.4) (2014-12-16) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.3...1.2.4) +## [1.2.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.4) - 16/12/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.3...1.2.4) - *Merged pull-request:* Implement async fetching [\#39](https://github.com/skywinder/Github-Changelog-Generator/pull/39) ([skywinder](https://github.com/skywinder)) @@ -37,8 +37,8 @@ - *Fixed bug:* Sometimes user is NULL during merges [\#41](https://github.com/skywinder/Github-Changelog-Generator/issues/41) -## [1.2.3](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3) (2014-12-16) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.2...1.2.3) +## [1.2.3](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3) - 16/12/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.2...1.2.3) - *Merged pull-request:* Fix crash when user is NULL [\#40](https://github.com/skywinder/Github-Changelog-Generator/pull/40) ([skywinder](https://github.com/skywinder)) @@ -48,15 +48,15 @@ - *Fixed bug:* Docs lacking or basic behavior not as advertised [\#30](https://github.com/skywinder/Github-Changelog-Generator/issues/30) -## [1.2.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.2) (2014-12-10) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.1...1.2.2) +## [1.2.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.2) - 10/12/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.1...1.2.2) - *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) (2014-11-22) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.0...1.2.1) +## [1.2.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.1) - 22/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.0...1.2.1) - *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)) @@ -64,8 +64,8 @@ - *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) (2014-11-19) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.4...1.2.0) +## [1.2.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.0) - 19/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.4...1.2.0) - *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)) @@ -75,22 +75,22 @@ - *Merged pull-request:* Don't receive issues in case of --no-isses flag specied [\#24](https://github.com/skywinder/Github-Changelog-Generator/pull/24) ([skywinder](https://github.com/skywinder)) -## [1.1.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.4) (2014-11-18) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.2...1.1.4) +## [1.1.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.4) - 18/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.2...1.1.4) - *Merged pull-request:* Sort tags by date [\#23](https://github.com/skywinder/Github-Changelog-Generator/pull/23) ([skywinder](https://github.com/skywinder)) - *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) -## [1.1.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.2) (2014-11-12) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.1...1.1.2) +## [1.1.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.2) - 12/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.1...1.1.2) - *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)) - *Merged pull-request:* Fix bug with dot signs in user name [\#17](https://github.com/skywinder/Github-Changelog-Generator/pull/17) ([skywinder](https://github.com/skywinder)) -## [1.1.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.1) (2014-11-10) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.0...1.1.1) +## [1.1.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.1) - 10/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.0...1.1.1) - *Merged pull-request:* Remove duplicates of issues and pull-requests with same number [\#15](https://github.com/skywinder/Github-Changelog-Generator/pull/15) ([skywinder](https://github.com/skywinder)) @@ -98,8 +98,8 @@ - *Merged pull-request:* Add ability to add or exclude issues without any labels [\#13](https://github.com/skywinder/Github-Changelog-Generator/pull/13) ([skywinder](https://github.com/skywinder)) -## [1.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.0) (2014-11-10) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.0.1...1.1.0) +## [1.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.0) - 10/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.0.1...1.1.0) - *Implemented enhancement:* Detect username and project form origin [\#11](https://github.com/skywinder/Github-Changelog-Generator/issues/11) @@ -107,13 +107,13 @@ - *Fixed bug:* Bug with wrong credentials in 1.0.1 [\#12](https://github.com/skywinder/Github-Changelog-Generator/issues/12) -## [1.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.1) (2014-11-10) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.0.0...1.0.1) +## [1.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.1) - 10/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.0.0...1.0.1) - *Merged pull-request:* Implement support of different tags. [\#8](https://github.com/skywinder/Github-Changelog-Generator/pull/8) ([skywinder](https://github.com/skywinder)) -## [1.0.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.0) (2014-11-07) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.1.0...1.0.0) +## [1.0.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.0) - 07/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.1.0...1.0.0) - *Merged pull-request:* Add support for issues in CHANGELOG [\#7](https://github.com/skywinder/Github-Changelog-Generator/pull/7) ([skywinder](https://github.com/skywinder)) @@ -125,17 +125,18 @@ - *Fixed bug:* Last tag not appeared in changelog [\#5](https://github.com/skywinder/Github-Changelog-Generator/issues/5) -## [0.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/0.1.0) (2014-11-07) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.0.2...0.1.0) +## [0.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/0.1.0) - 07/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.0.2...0.1.0) - *Merged pull-request:* Add changelog generation for last tag [\#2](https://github.com/skywinder/Github-Changelog-Generator/pull/2) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Add option \(-o --output\) to specify name of the output file. [\#1](https://github.com/skywinder/Github-Changelog-Generator/pull/1) ([skywinder](https://github.com/skywinder)) -## [0.0.2](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2) (2014-11-06) -[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.0.1...0.0.2) +## [0.0.2](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2) - 06/11/14 +#### [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.0.1...0.0.2) + +## [0.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.1) - 06/11/14 -## [0.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.1) (2014-11-06) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index e27325d..b871213 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -57,7 +57,7 @@ module GitHubChangelogGenerator end threads = [] - @issues.each{|issue| + @issues.each { |issue| threads << Thread.new { find_closed_date_by_commit(issue) } @@ -72,7 +72,7 @@ module GitHubChangelogGenerator def find_closed_date_by_commit(issue) unless issue['events'].nil? # reverse! - to find latest closed event. (event goes in date order) - issue['events'].reverse!.each{|event| + issue['events'].reverse!.each { |event| if event[:event].eql? 'closed' if event[:commit_id].nil? issue[:actual_date] = issue[:closed_at] @@ -162,8 +162,8 @@ module GitHubChangelogGenerator log = "# Changelog\n\n" - if @options[:last] - log += self.generate_log_between_tags(self.all_tags[0], self.all_tags[1]) + if @options[:unreleased] + log += self.generate_log_between_tags(self.all_tags[0], nil) elsif @options[:tag1] and @options[:tag2] tag1 = @options[:tag1] tag2 = @options[:tag2] @@ -278,66 +278,67 @@ module GitHubChangelogGenerator def generate_log_between_tags(older_tag, newer_tag) - if newer_tag.nil? - puts "Can't find tag -> terminate" - exit 1 + filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, older_tag, newer_tag) + filtered_issues = delete_by_time(@issues, :actual_date, older_tag, newer_tag) + + unless newer_tag.nil? + newer_tag_name = newer_tag['name'] + + if @options[:filter_issues_by_milestone] + #delete excess irrelevant issues (according milestones) + 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 end - newer_tag_time = self.get_time_of_tag(newer_tag) - newer_tag_name = newer_tag['name'] + older_tag_name = older_tag.nil? ? nil : older_tag['name'] - filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag) - filtered_issues = delete_by_time(@issues, :actual_date, newer_tag_time, older_tag) - - older_tag_name = older_tag.nil? ? nil : older_tag['name'] - - if @options[:filter_issues_by_milestone] - #delete excess irrelevant issues (according milestones) - 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) + self.create_log(filtered_pull_requests, filtered_issues, newer_tag, older_tag_name) end def filter_by_milestone(filtered_issues, newer_tag_name, src_array) + + filtered_issues.select! { |issue| + # leave issues without milestones 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? + @all_tags.find { |tag| tag.name == issue.milestone.title }.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 - } + unless newer_tag_name.nil? - if milestone_is_tag.nil? + #add missed issues (according milestones) + issues_to_add = src_array.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 end - def delete_by_time(array, hash_key, newer_tag_time, older_tag = nil) + def delete_by_time(array, hash_key, older_tag = nil, newer_tag = nil) + raise 'At least on of the tags should be not nil!' if (older_tag.nil? && newer_tag.nil?) + + newer_tag_time = self.get_time_of_tag(newer_tag) older_tag_time = self.get_time_of_tag(older_tag) array.select { |req| @@ -350,7 +351,12 @@ module GitHubChangelogGenerator tag_in_range_old = t > older_tag_time end - tag_in_range_new = t <= newer_tag_time + if newer_tag_time.nil? + tag_in_range_new = true + else + tag_in_range_new = t <= newer_tag_time + end + tag_in_range = (tag_in_range_old) && (tag_in_range_new) @@ -363,26 +369,33 @@ module GitHubChangelogGenerator # @param [Array] pull_requests # @param [Array] issues - # @param [String] newer_tag_name - # @param [String] newer_tag_time # @param [String] older_tag_name # @return [String] - def create_log(pull_requests, issues, newer_tag_name, newer_tag_time, older_tag_name = nil) + def create_log(pull_requests, issues, newer_tag, older_tag_name = nil) + + newer_tag_time = newer_tag.nil? ? nil : self.get_time_of_tag(newer_tag) + newer_tag_name = newer_tag.nil? ? nil : newer_tag['name'] github_site = options[:github_site] || 'https://github.com' - project_url = "#{github_site}/#{@options[:user]}/#{@options[:project]}" + if newer_tag.nil? + newer_tag_name = 'Unreleased' + newer_tag_name2 = 'HEAD' + newer_tag_time = Time.new + else + newer_tag_name2 = newer_tag_name + end + #Generate date string: time_string = newer_tag_time.strftime @options[:format] # Generate tag name and link - log = "## [#{newer_tag_name}](#{project_url}/tree/#{newer_tag_name}) (#{time_string})\n" - + log = "## [#{newer_tag_name}](#{project_url}/tree/#{newer_tag_name2}) (#{time_string})\n" if @options[:compare_link] && older_tag_name # Generate compare link - log += "[Full Changelog](#{project_url}/compare/#{older_tag_name}...#{newer_tag_name})\n\n" + log += "[Full Changelog](#{project_url}/compare/#{older_tag_name}...#{newer_tag_name2})\n\n" else log += "\n" end @@ -442,6 +455,7 @@ module GitHubChangelogGenerator log += "- #{merge}" } end + log end diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 784ed2f..5ae4cea 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -41,7 +41,10 @@ module GitHubChangelogGenerator 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 + options[:author] = author + end + opts.on('--unreleased', 'Generate log from unreleased closed issues.') do |v| + options[:unreleased] = v end opts.on('--[no-]compare-link', 'Include compare link between older version and newer version. Default is true') do |v| options[:compare_link] = v