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
## [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)
[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:* 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)
## [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
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_only]
log += self.generate_log_between_tags(self.all_tags[0], nil)
elsif @options[:tag1] and @options[:tag2]
tag1 = @options[:tag1]
tag2 = @options[:tag2]
@ -222,6 +222,10 @@ module GitHubChangelogGenerator
puts "Generating log.."
end
if @options[:unreleased]
log += self.generate_log_between_tags(self.all_tags[0], nil)
end
(1 ... self.all_tags.size).each { |index|
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)
if newer_tag.nil?
puts "Can't find tag -> terminate"
exit 1
end
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)
newer_tag_time = self.get_time_of_tag(newer_tag)
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']
newer_tag_name = newer_tag.nil? ? nil : newer_tag['name']
if @options[:filter_issues_by_milestone]
#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)
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
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
}
unless newer_tag_name.nil?
#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?
#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
filtered_issues
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

View File

@ -6,7 +6,7 @@ require_relative 'version'
module GitHubChangelogGenerator
class Parser
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|
opts.banner = 'Usage: changelog_generator [options]'
@ -41,7 +41,13 @@ 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-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
opts.on('--[no-]compare-link', 'Include compare link between older version and newer version. Default is true') do |v|
options[:compare_link] = v