Merge branch 'feature/fix-52' into develop

This commit is contained in:
Petr Korolev 2015-02-18 23:33:53 +02:00
commit 5422e58508
3 changed files with 149 additions and 71 deletions

View File

@ -5,8 +5,6 @@
- *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)) - *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)
@ -78,8 +76,6 @@
- *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)) - *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))
- *Merged pull-request:* Test Pull-Request SHOULD NOT APPEAR IN LOG! [\#26](https://github.com/skywinder/Github-Changelog-Generator/pull/26) ([skywinder](https://github.com/skywinder))
- *Merged pull-request:* Add ability to insert authors of pull-requests \(--\[no-\]author option\) [\#25](https://github.com/skywinder/Github-Changelog-Generator/pull/25) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Add ability to insert authors of pull-requests \(--\[no-\]author option\) [\#25](https://github.com/skywinder/Github-Changelog-Generator/pull/25) ([skywinder](https://github.com/skywinder))
- *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)) - *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))

View File

@ -38,9 +38,17 @@ module GitHubChangelogGenerator
@generator = Generator.new(@options) @generator = Generator.new(@options)
@all_tags = self.get_all_tags @all_tags = self.get_all_tags
@issues, @pull_requests = self.fetch_issues_and_pull_requests
if @options[:pulls]
@pull_requests = self.get_filtered_pull_requests @pull_requests = self.get_filtered_pull_requests
self.fetch_merged_at_pull_requests
else
@pull_requests = []
end
if @options[:issues] if @options[:issues]
@issues = self.get_all_issues @issues = self.get_filtered_issues
fetch_event_for_issues(@issues) fetch_event_for_issues(@issues)
detect_actual_closed_dates detect_actual_closed_dates
else else
@ -96,7 +104,7 @@ module GitHubChangelogGenerator
%x[#{exec_cmd}] %x[#{exec_cmd}]
end end
def get_all_closed_pull_requests def fetch_merged_at_pull_requests
if @options[:verbose] if @options[:verbose]
print "Fetching pull requests...\r" print "Fetching pull requests...\r"
end end
@ -116,46 +124,85 @@ module GitHubChangelogGenerator
puts "Received pull requests: #{pull_requests.count}" puts "Received pull requests: #{pull_requests.count}"
end end
pull_requests @pull_requests.each{|pr|
fetched_pr = pull_requests.find{ |fpr|
fpr.number == pr.number }
pr[:merged_at] = fetched_pr[:merged_at]
pull_requests.delete(fetched_pr)
}
end end
def get_filtered_pull_requests def get_filtered_pull_requests
pull_requests = self.get_all_closed_pull_requests pull_requests = @pull_requests
filtered_pull_requests = pull_requests
unless @options[:pull_request_labels].nil?
if @options[:verbose] unless @options[:include_labels].nil?
puts 'Filter all pull requests by labels.' filtered_pull_requests = pull_requests.select { |issue|
end #add all labels from @options[:incluse_labels] array
(issue.labels.map { |label| label.name } & @options[:include_labels]).any?
filtered_pull_requests = pull_requests.select { |pull_request|
#fetch this issue to get labels array
issue = @github.issues.get @options[:user], @options[:project], pull_request.number
#compare is there any labels from @options[:labels] array
issue_without_labels = !issue.labels.map { |label| label.name }.any?
if @options[:verbose]
puts "Filter request \##{issue.number}."
end
if @options[:pull_request_labels].any?
select_by_label = (issue.labels.map { |label| label.name } & @options[:pull_request_labels]).any?
else
select_by_label = false
end
select_by_label | issue_without_labels
} }
end
unless @options[:exclude_labels].nil?
filtered_pull_requests = filtered_pull_requests.select { |issue|
#delete all labels from @options[:exclude_labels] array
!(issue.labels.map { |label| label.name } & @options[:exclude_labels]).any?
}
end
if @options[:add_issues_wo_labels]
issues_wo_labels = pull_requests.select {
# add issues without any labels
|issue| !issue.labels.map { |label| label.name }.any?
}
filtered_pull_requests |= issues_wo_labels
end
if @options[:verbose] if @options[:verbose]
puts "Filtered pull requests with specified labels and w/o labels: #{filtered_pull_requests.count}" puts "Filtered pull requests: #{filtered_pull_requests.count}"
end
return filtered_pull_requests
end end
pull_requests filtered_pull_requests
#
# #
#
#
# unless @options[:pull_request_labels].nil?
#
# if @options[:verbose]
# puts 'Filter all pull requests by labels.'
# end
#
# filtered_pull_requests = filtered_pull_requests.select { |pull_request|
# #fetch this issue to get labels array
# issue = @github.issues.get @options[:user], @options[:project], pull_request.number
#
# #compare is there any labels from @options[:labels] array
# issue_without_labels = !issue.labels.map { |label| label.name }.any?
#
# if @options[:verbose]
# puts "Filter request \##{issue.number}."
# end
#
# if @options[:pull_request_labels].any?
# select_by_label = (issue.labels.map { |label| label.name } & @options[:pull_request_labels]).any?
# else
# select_by_label = false
# end
#
# select_by_label | issue_without_labels
# }
#
# if @options[:verbose]
# puts "Filtered pull requests with specified labels and w/o labels: #{filtered_pull_requests.count}"
# end
# return filtered_pull_requests
# end
#
# filtered_pull_requests
end end
def compund_changelog def compund_changelog
@ -192,8 +239,8 @@ module GitHubChangelogGenerator
output_filename = "#{@options[:output]}" output_filename = "#{@options[:output]}"
File.open(output_filename, 'w') { |file| file.write(log) } File.open(output_filename, 'w') { |file| file.write(log) }
puts 'Done!'
puts "Done! Generated log placed in #{`pwd`.strip!}/#{output_filename}" puts "Generated log placed in #{`pwd`.strip!}/#{output_filename}"
end end
@ -201,17 +248,30 @@ module GitHubChangelogGenerator
log = '' log = ''
if @options[:verbose] if @options[:verbose]
puts "Fetching tags dates.." print "Fetching tags dates..\r"
end end
# Async fetching tags: # Async fetching tags:
threads = [] threads = []
i = 0
all = @all_tags.count
@all_tags.each { |tag| @all_tags.each { |tag|
# explicit set @tag_times_hash to write data safety. # explicit set @tag_times_hash to write data safety.
threads << Thread.new { self.get_time_of_tag(tag, @tag_times_hash) } threads << Thread.new {
self.get_time_of_tag(tag, @tag_times_hash)
if @options[:verbose]
i+=1
print "Fetching tags dates: #{i+1}/#{all}\r"
end
} }
}
threads.each { |thr| thr.join } threads.each { |thr| thr.join }
if @options[:verbose]
puts 'Fetching tags: Done!'
end
if @options[:verbose] if @options[:verbose]
puts "Sorting tags.." puts "Sorting tags.."
end end
@ -474,8 +534,44 @@ module GitHubChangelogGenerator
@tag_times_hash[tag_name['name']] = Time.parse(time_string) @tag_times_hash[tag_name['name']] = Time.parse(time_string)
end end
def get_all_issues def get_filtered_issues
issues = @issues
filtered_issues = issues
unless @options[:include_labels].nil?
filtered_issues = issues.select { |issue|
#add all labels from @options[:incluse_labels] array
(issue.labels.map { |label| label.name } & @options[:include_labels]).any?
}
end
unless @options[:exclude_labels].nil?
filtered_issues = filtered_issues.select { |issue|
#delete all labels from @options[:exclude_labels] array
!(issue.labels.map { |label| label.name } & @options[:exclude_labels]).any?
}
end
if @options[:add_issues_wo_labels]
issues_wo_labels = issues.select {
# add issues without any labels
|issue| !issue.labels.map { |label| label.name }.any?
}
filtered_issues |= issues_wo_labels
end
if @options[:verbose]
puts "Filtered issues: #{filtered_issues.count}"
end
filtered_issues
end
def fetch_issues_and_pull_requests
if @options[:verbose] if @options[:verbose]
print "Fetching closed issues...\r" print "Fetching closed issues...\r"
end end
@ -498,31 +594,13 @@ module GitHubChangelogGenerator
end end
# remove pull request from issues: # remove pull request from issues:
issues.select! { |x| issues_wo_pr = issues.select { |x|
x.pull_request == nil x.pull_request == nil
} }
pull_requests = issues.select { |x|
filtered_issues = issues.select { |issue| x.pull_request != nil
#compare is there any labels from @options[:labels] array
(issue.labels.map { |label| label.name } & @options[:labels]).any?
} }
return issues_wo_pr, pull_requests
if @options[:add_issues_wo_labels]
issues_wo_labels = issues.select {
# add issues without any labels
|issue| !issue.labels.map { |label| label.name }.any?
}
filtered_issues.concat(issues_wo_labels)
end
if @options[:verbose]
puts "Filtered issues with labels #{@options[:labels]}#{@options[:add_issues_wo_labels] ? ' and w/o labels' : ''}: #{filtered_issues.count}"
end
filtered_issues
end end
def fetch_event_for_issues(filtered_issues) def fetch_event_for_issues(filtered_issues)

View File

@ -6,7 +6,8 @@ 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, :unreleased => true} # :include_labels => %w(bug enhancement),
options = {:tag1 => nil, :tag2 => nil, :format => '%Y-%m-%d', :output => 'CHANGELOG.md', :exclude_labels => %w(duplicate question invalid wontfix), :pulls => true, :issues => true, :verbose => true, :add_issues_wo_labels => true, :add_pr_wo_labels => true, :merge_prefix => '*Merged pull-request:* ', :author => true, :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]'
@ -31,9 +32,12 @@ module GitHubChangelogGenerator
opts.on('--[no-]issues', 'Include closed issues to changelog. Default is true') do |v| opts.on('--[no-]issues', 'Include closed issues to changelog. Default is true') do |v|
options[:issues] = v options[:issues] = v
end end
opts.on('--[no-]issues-wo-labels', 'Include closed issues without any labels to changelog. Default is true') do |v| opts.on('--[no-]issues-wo-labels', 'Include closed issues without labels to changelog. Default is true') do |v|
options[:add_issues_wo_labels] = v options[:add_issues_wo_labels] = v
end end
opts.on('--[no-]pr-wo-labels', 'Include pull requests without labels to changelog. Default is true') do |v|
options[:add_pr_wo_labels] = v
end
opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v| opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v|
options[:pulls] = v options[:pulls] = v
end end
@ -52,11 +56,11 @@ module GitHubChangelogGenerator
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
end end
opts.on('--labels x,y,z', Array, 'Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list| opts.on('--include-labels x,y,z', Array, 'Issues only with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
options[:labels] = list options[:include_labels] = list
end end
opts.on('--labels-pr x,y,z', Array, 'Only pull requests with specified labels will be included to changelog. Default is nil') do |list| opts.on('--exclude-labels x,y,z', Array, 'Issues with that labels will be always excluded from changelog. Default is \'duplicate,question,invalid,wontfix\'') do |list|
options[:pull_request_labels] = list options[:exclude_labels] = list
end end
opts.on('--github-site [URL]', 'The Enterprise Github site on which your project is hosted.') do |last| opts.on('--github-site [URL]', 'The Enterprise Github site on which your project is hosted.') do |last|
options[:github_site] = last options[:github_site] = last