implement "issues" parsing + check for merged requests
This commit is contained in:
parent
8457b764bf
commit
f9e6a076bc
|
@ -8,7 +8,7 @@ require_relative 'github_changelog_generator/parser'
|
||||||
|
|
||||||
class ChangelogGenerator
|
class ChangelogGenerator
|
||||||
|
|
||||||
attr_accessor :options, :all_tags
|
attr_accessor :options, :all_tags, :github
|
||||||
|
|
||||||
def initialize()
|
def initialize()
|
||||||
|
|
||||||
|
@ -35,17 +35,14 @@ class ChangelogGenerator
|
||||||
|
|
||||||
|
|
||||||
def get_all_closed_pull_requests
|
def get_all_closed_pull_requests
|
||||||
|
request = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
||||||
|
pull_requests = request.body
|
||||||
issues = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
|
||||||
json = issues.body
|
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts 'Receive all pull requests'
|
puts 'Receive all pull requests'
|
||||||
end
|
end
|
||||||
|
|
||||||
json
|
pull_requests
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def compund_changelog
|
def compund_changelog
|
||||||
|
@ -87,7 +84,7 @@ class ChangelogGenerator
|
||||||
puts log
|
puts log
|
||||||
end
|
end
|
||||||
|
|
||||||
log += "\n\n*This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
|
log += "\n\n**This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
|
||||||
|
|
||||||
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) }
|
||||||
|
@ -111,19 +108,6 @@ class ChangelogGenerator
|
||||||
@github.pull_requests.merged? @options[:user], @options[:project], number
|
@github.pull_requests.merged? @options[:user], @options[:project], number
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_all_merged_pull_requests
|
|
||||||
json = self.get_all_closed_pull_requests
|
|
||||||
puts 'Check if the requests is merged... (it can take a while)'
|
|
||||||
|
|
||||||
json.delete_if { |req|
|
|
||||||
merged = self.is_megred(req[:number])
|
|
||||||
if @options[:verbose]
|
|
||||||
puts "##{req[:number]} #{merged ? 'merged' : 'not merged'}"
|
|
||||||
end
|
|
||||||
!merged
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_all_tags
|
def get_all_tags
|
||||||
|
|
||||||
url = "https://api.github.com/repos/#{@options[:user]}/#{@options[:project]}/tags"
|
url = "https://api.github.com/repos/#{@options[:user]}/#{@options[:project]}/tags"
|
||||||
|
@ -133,7 +117,7 @@ class ChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
response = HTTParty.get(url,
|
response = HTTParty.get(url,
|
||||||
:headers => {'Authorization' => 'token 8587bb22f6bf125454768a4a19dbcc774ea68d48',
|
:headers => {'Authorization' => "token #{@options[:token]}",
|
||||||
'User-Agent' => 'Changelog-Generator'})
|
'User-Agent' => 'Changelog-Generator'})
|
||||||
|
|
||||||
json_parse = JSON.parse(response.body)
|
json_parse = JSON.parse(response.body)
|
||||||
|
@ -160,12 +144,17 @@ class ChangelogGenerator
|
||||||
pull_requests = Array.new(@pull_requests)
|
pull_requests = Array.new(@pull_requests)
|
||||||
|
|
||||||
pull_requests.delete_if { |req|
|
pull_requests.delete_if { |req|
|
||||||
t = Time.parse(req[:merged_at]).utc
|
if req[:merged_at]
|
||||||
tag_is_later_since = t > since_tag_time
|
t = Time.parse(req[:merged_at]).utc
|
||||||
tag_is_before_till = t <= till_tag_time
|
tag_is_later_since = t > since_tag_time
|
||||||
|
tag_is_before_till = t <= till_tag_time
|
||||||
|
|
||||||
|
in_range = (tag_is_later_since) && (tag_is_before_till)
|
||||||
|
!in_range
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
in_range = (tag_is_later_since) && (tag_is_before_till)
|
|
||||||
!in_range
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.create_log(pull_requests, till_tag_name, till_tag_time)
|
self.create_log(pull_requests, till_tag_name, till_tag_time)
|
||||||
|
@ -217,10 +206,20 @@ class ChangelogGenerator
|
||||||
@tag_times_hash[prev_tag['name']] = Time.parse(time_string)
|
@tag_times_hash[prev_tag['name']] = Time.parse(time_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_all_issues
|
||||||
|
all_issues = []
|
||||||
|
@options[:labels].each { |label|
|
||||||
|
issues = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: label
|
||||||
|
all_issues = all_issues.concat(issues.body)
|
||||||
|
}
|
||||||
|
all_issues
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if __FILE__ == $0
|
if __FILE__ == $0
|
||||||
changelog_generator = ChangelogGenerator.new
|
changelog_generator = ChangelogGenerator.new
|
||||||
# changelog_generator.compund_changelog
|
changelog_generator.compund_changelog
|
||||||
|
changelog_generator.get_all_issues
|
||||||
end
|
end
|
|
@ -3,7 +3,7 @@ require 'optparse'
|
||||||
|
|
||||||
class Parser
|
class Parser
|
||||||
def self.parse_options
|
def self.parse_options
|
||||||
options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md'}
|
options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement)}
|
||||||
|
|
||||||
parser = OptionParser.new { |opts|
|
parser = OptionParser.new { |opts|
|
||||||
opts.banner = 'Usage: changelog_generator --user username --project project_name [options]'
|
opts.banner = 'Usage: changelog_generator --user username --project project_name [options]'
|
||||||
|
@ -23,7 +23,10 @@ class Parser
|
||||||
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
||||||
options[:verbose] = v
|
options[:verbose] = v
|
||||||
end
|
end
|
||||||
opts.on('-l', '--last-changes', 'Generate log between only last 2 tags') do |last|
|
opts.on('-i', '--[no-]issues', 'Include closed issues to changelog') do |v|
|
||||||
|
options[:issues] = v
|
||||||
|
end
|
||||||
|
opts.on('-l', '--last-changes', 'Generate log between last 2 tags only') do |last|
|
||||||
options[:last] = last
|
options[:last] = last
|
||||||
end
|
end
|
||||||
opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last|
|
opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last|
|
||||||
|
@ -32,6 +35,9 @@ class Parser
|
||||||
opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last|
|
opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last|
|
||||||
options[:output] = last
|
options[:output] = last
|
||||||
end
|
end
|
||||||
|
opts.on('--labels x,y,z', Array, 'List of labels. Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
|
||||||
|
options[:labels] = list
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.parse!
|
parser.parse!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user