Merge branch 'feature/fix-47' into develop

This commit is contained in:
Petr Korolev 2015-02-18 21:47:31 +02:00
commit 904017cf4d
3 changed files with 77 additions and 48 deletions

View File

@ -1,10 +1,19 @@
# Changelog # Changelog
## [Unreleased](https://github.com/skywinder/Github-Changelog-Generator/tree/HEAD) (2015-02-18)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.8...HEAD)
- *Merged pull-request:* Implement filtering of Pull Requests by milestones [\#50](https://github.com/skywinder/Github-Changelog-Generator/pull/50) ([skywinder](https://github.com/skywinder))
- *Implemented enhancement:* Add support for forked repo \(to extend changelog with parent's changes\) [\#21](https://github.com/skywinder/Github-Changelog-Generator/issues/21)
## [1.2.8](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.8) (2015-02-17) ## [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) [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)) - *Merged pull-request:* Feature/fix 37 [\#49](https://github.com/skywinder/Github-Changelog-Generator/pull/49) ([skywinder](https://github.com/skywinder))
- *Merged pull-request:* Prettify output [\#48](https://github.com/skywinder/Github-Changelog-Generator/pull/48) ([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) - *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) ## [1.2.7](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.7) (2015-01-26)

View File

@ -57,7 +57,7 @@ module GitHubChangelogGenerator
end end
threads = [] threads = []
@issues.each{|issue| @issues.each { |issue|
threads << Thread.new { threads << Thread.new {
find_closed_date_by_commit(issue) find_closed_date_by_commit(issue)
} }
@ -72,7 +72,7 @@ module GitHubChangelogGenerator
def find_closed_date_by_commit(issue) def find_closed_date_by_commit(issue)
unless issue['events'].nil? unless issue['events'].nil?
# reverse! - to find latest closed event. (event goes in date order) # 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[:event].eql? 'closed'
if event[:commit_id].nil? if event[:commit_id].nil?
issue[:actual_date] = issue[:closed_at] issue[:actual_date] = issue[:closed_at]
@ -162,8 +162,8 @@ module GitHubChangelogGenerator
log = "# Changelog\n\n" log = "# Changelog\n\n"
if @options[:last] if @options[:unreleased_only]
log += self.generate_log_between_tags(self.all_tags[0], self.all_tags[1]) log += self.generate_log_between_tags(self.all_tags[0], nil)
elsif @options[:tag1] and @options[:tag2] elsif @options[:tag1] and @options[:tag2]
tag1 = @options[:tag1] tag1 = @options[:tag1]
tag2 = @options[:tag2] tag2 = @options[:tag2]
@ -222,6 +222,10 @@ module GitHubChangelogGenerator
puts "Generating log.." puts "Generating log.."
end end
if @options[:unreleased]
log += self.generate_log_between_tags(self.all_tags[0], nil)
end
(1 ... self.all_tags.size).each { |index| (1 ... self.all_tags.size).each { |index|
log += self.generate_log_between_tags(self.all_tags[index], self.all_tags[index-1]) log += self.generate_log_between_tags(self.all_tags[index], self.all_tags[index-1])
} }
@ -278,18 +282,10 @@ module GitHubChangelogGenerator
def generate_log_between_tags(older_tag, newer_tag) def generate_log_between_tags(older_tag, newer_tag)
if newer_tag.nil? filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, older_tag, newer_tag)
puts "Can't find tag -> terminate" filtered_issues = delete_by_time(@issues, :actual_date, older_tag, newer_tag)
exit 1
end
newer_tag_time = self.get_time_of_tag(newer_tag) newer_tag_name = newer_tag.nil? ? nil : newer_tag['name']
newer_tag_name = newer_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] if @options[:filter_issues_by_milestone]
#delete excess irrelevant issues (according milestones) #delete excess irrelevant issues (according milestones)
@ -297,47 +293,52 @@ module GitHubChangelogGenerator
filtered_pull_requests = filter_by_milestone(filtered_pull_requests, newer_tag_name, @pull_requests) filtered_pull_requests = filter_by_milestone(filtered_pull_requests, newer_tag_name, @pull_requests)
end end
self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time, older_tag_name) older_tag_name = older_tag.nil? ? nil : older_tag['name']
self.create_log(filtered_pull_requests, filtered_issues, newer_tag, older_tag_name)
end end
def filter_by_milestone(filtered_issues, newer_tag_name, src_array) def filter_by_milestone(filtered_issues, newer_tag_name, src_array)
filtered_issues.select! { |issue| filtered_issues.select! { |issue|
# leave issues without milestones
if issue.milestone.nil? if issue.milestone.nil?
true true
else else
#check, that this milestone in tag list: #check, that this milestone in tag list:
milestone_is_tag = @all_tags.find { |tag| @all_tags.find { |tag| tag.name == issue.milestone.title }.nil?
tag.name == issue.milestone.title
}
milestone_is_tag.nil?
end end
} }
unless newer_tag_name.nil?
#add missed issues (according milestones) #add missed issues (according milestones)
issues_to_add = src_array.select { |issue| issues_to_add = src_array.select { |issue|
if issue.milestone.nil? 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 false
else else
issue.milestone.title == newer_tag_name #check, that this milestone in tag list:
end milestone_is_tag = @all_tags.find { |tag|
end 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
filtered_issues
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) older_tag_time = self.get_time_of_tag(older_tag)
array.select { |req| array.select { |req|
@ -350,7 +351,12 @@ module GitHubChangelogGenerator
tag_in_range_old = t > older_tag_time tag_in_range_old = t > older_tag_time
end 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) tag_in_range = (tag_in_range_old) && (tag_in_range_new)
@ -363,26 +369,33 @@ module GitHubChangelogGenerator
# @param [Array] pull_requests # @param [Array] pull_requests
# @param [Array] issues # @param [Array] issues
# @param [String] newer_tag_name
# @param [String] newer_tag_time
# @param [String] older_tag_name # @param [String] older_tag_name
# @return [String] # @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' github_site = options[:github_site] || 'https://github.com'
project_url = "#{github_site}/#{@options[:user]}/#{@options[:project]}" 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: #Generate date string:
time_string = newer_tag_time.strftime @options[:format] time_string = newer_tag_time.strftime @options[:format]
# Generate tag name and link # 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 if @options[:compare_link] && older_tag_name
# Generate compare link # 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 else
log += "\n" log += "\n"
end end
@ -442,6 +455,7 @@ module GitHubChangelogGenerator
log += "- #{merge}" log += "- #{merge}"
} }
end end
log log
end end

View File

@ -6,7 +6,7 @@ require_relative 'version'
module GitHubChangelogGenerator module GitHubChangelogGenerator
class Parser class Parser
def self.parse_options def self.parse_options
options = {:tag1 => nil, :tag2 => nil, :format => '%Y-%m-%d', :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, :compare_link => true} options = {:tag1 => nil, :tag2 => nil, :format => '%Y-%m-%d', :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, :compare_link => true, :unreleased => true}
parser = OptionParser.new { |opts| parser = OptionParser.new { |opts|
opts.banner = 'Usage: changelog_generator [options]' opts.banner = 'Usage: changelog_generator [options]'
@ -41,7 +41,13 @@ module GitHubChangelogGenerator
options[:filter_issues_by_milestone] = last options[:filter_issues_by_milestone] = last
end end
opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author| 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-only', 'Generate log from unreleased closed issues only.') do |v|
options[:unreleased_only] = v
end
opts.on('--[no-]unreleased', 'Add to log unreleased closed issues. Default is true') do |v|
options[:unreleased] = v
end end
opts.on('--[no-]compare-link', 'Include compare link between older version and newer version. Default is true') do |v| opts.on('--[no-]compare-link', 'Include compare link between older version and newer version. Default is true') do |v|
options[:compare_link] = v options[:compare_link] = v