refactoring

This commit is contained in:
Petr Korolev 2015-02-18 22:21:00 +02:00
parent 1d7f09e9bb
commit 563ddb7f30
2 changed files with 38 additions and 30 deletions

View File

@ -40,7 +40,7 @@ module GitHubChangelogGenerator
@all_tags = self.get_all_tags
@pull_requests = self.get_filtered_pull_requests
if @options[:issues]
@issues = self.get_all_issues
@issues = self.get_filtered_issues
fetch_event_for_issues(@issues)
detect_actual_closed_dates
else
@ -474,33 +474,9 @@ module GitHubChangelogGenerator
@tag_times_hash[tag_name['name']] = Time.parse(time_string)
end
def get_all_issues
def get_filtered_issues
if @options[:verbose]
print "Fetching closed issues...\r"
end
response = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
issues = []
page_i = 0
count_pages = response.count_pages
response.each_page do |page|
page_i += PER_PAGE_NUMBER
print "Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\r"
issues.concat(page)
end
print " \r"
if @options[:verbose]
puts "Received issues: #{issues.count}"
end
# remove pull request from issues:
issues.select! { |x|
x.pull_request == nil
}
issues = self.get_all_issues
filtered_issues = issues
@ -528,13 +504,42 @@ module GitHubChangelogGenerator
if @options[:verbose]
puts "Filtered issues with labels #{@options[:include_labels]}#{@options[:add_issues_wo_labels] ? ' and w/o labels' : ''}: #{filtered_issues.count}"
puts "Filtered issues: #{filtered_issues.count}"
end
filtered_issues
end
def get_all_issues
if @options[:verbose]
print "Fetching closed issues...\r"
end
response = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
issues = []
page_i = 0
count_pages = response.count_pages
response.each_page do |page|
page_i += PER_PAGE_NUMBER
print "Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\r"
issues.concat(page)
end
print " \r"
if @options[:verbose]
puts "Received issues: #{issues.count}"
end
# remove pull request from issues:
issues.select! { |x|
x.pull_request == nil
}
issues
end
def fetch_event_for_issues(filtered_issues)
if @options[:verbose]
print "Fetching events for issues: 0/#{filtered_issues.count}\r"

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', :exclude_labels => %w(duplicate question invalid wontfix), :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}
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, :pull_request_labels => nil, :filter_issues_by_milestone => true, :compare_link => true, :unreleased => true}
parser = OptionParser.new { |opts|
opts.banner = 'Usage: changelog_generator [options]'
@ -31,9 +31,12 @@ module GitHubChangelogGenerator
opts.on('--[no-]issues', 'Include closed issues to changelog. Default is true') do |v|
options[:issues] = v
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
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|
options[:pulls] = v
end