complete migrate to git api
This commit is contained in:
parent
61ffde6714
commit
e6acf85a63
|
@ -7,15 +7,9 @@ require_relative 'parser'
|
||||||
def run_generator options
|
def run_generator options
|
||||||
generator = LogGenerator.new(options)
|
generator = LogGenerator.new(options)
|
||||||
|
|
||||||
tag_time = generator.find_prev_tag_date
|
prev_tag = generator.find_prev_tag
|
||||||
pull_requests = generator.get_all_closed_pull_requests
|
|
||||||
|
|
||||||
pull_requests.delete_if { |req|
|
generator.compund_changelog(prev_tag)
|
||||||
t = Time.parse(req[:closed_at]).utc
|
|
||||||
t < tag_time
|
|
||||||
}
|
|
||||||
|
|
||||||
generator.compund_changelog(tag_time, pull_requests)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if __FILE__ == $0
|
if __FILE__ == $0
|
||||||
|
|
|
@ -5,7 +5,7 @@ require 'httparty'
|
||||||
|
|
||||||
class LogGenerator
|
class LogGenerator
|
||||||
|
|
||||||
attr_accessor :options
|
attr_accessor :options, :all_tags
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = options
|
@options = options
|
||||||
|
@ -14,6 +14,7 @@ class LogGenerator
|
||||||
else
|
else
|
||||||
@github = Github.new
|
@github = Github.new
|
||||||
end
|
end
|
||||||
|
@all_tags = self.get_all_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_json(json)
|
def print_json(json)
|
||||||
|
@ -25,27 +26,9 @@ class LogGenerator
|
||||||
%x[#{exec_cmd}]
|
%x[#{exec_cmd}]
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_prev_tag_date
|
def find_prev_tag
|
||||||
|
var = self.all_tags[1]
|
||||||
value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag"
|
p var
|
||||||
unless value1
|
|
||||||
puts 'not found this tag'
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
scan_results = value1.scan(/.*tag.*/)
|
|
||||||
|
|
||||||
prev_tag = scan_results[1]
|
|
||||||
|
|
||||||
unless scan_results.any?
|
|
||||||
puts 'Not found any versions -> exit'
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
if @options[:verbose]
|
|
||||||
puts "Prev tag is #{prev_tag}"
|
|
||||||
end
|
|
||||||
time = Time.parse(prev_tag)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,22 +48,14 @@ class LogGenerator
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def compund_changelog(tag_time, pull_requests)
|
def compund_changelog(prev_tag)
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts 'Generating changelog:'
|
puts 'Generating changelog:'
|
||||||
end
|
end
|
||||||
log = ''
|
log = ''
|
||||||
last_tag = exec_command('git describe --abbrev=0 --tags').strip
|
last_tag = self.all_tags[0]
|
||||||
log += "## [#{last_tag}] (https://github.com/#{$github_user}/#{$github_repo_name}/tree/#{last_tag})\n"
|
|
||||||
|
|
||||||
time_string = tag_time.strftime "%Y/%m/%d"
|
|
||||||
log += "#### #{time_string}\n"
|
|
||||||
|
|
||||||
pull_requests.each { |dict|
|
|
||||||
merge = "#{dict[:title]} ([\\##{dict[:number]}](https://github.com/#{$github_user}/#{$github_repo_name}/pull/#{dict[:number]}))\n"
|
|
||||||
log += "- #{merge}"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
log += self.generate_log_between_tags(prev_tag, last_tag)
|
||||||
puts log
|
puts log
|
||||||
File.open('output.txt', 'w') { |file| file.write(log) }
|
File.open('output.txt', 'w') { |file| file.write(log) }
|
||||||
|
|
||||||
|
@ -111,8 +86,38 @@ class LogGenerator
|
||||||
"User-Agent" => "APPLICATION_NAME"})
|
"User-Agent" => "APPLICATION_NAME"})
|
||||||
|
|
||||||
json_parse = JSON.parse(response.body)
|
json_parse = JSON.parse(response.body)
|
||||||
|
end
|
||||||
|
|
||||||
json_parse.each { |obj| p obj['name'] }
|
def generate_log_between_tags(prev_tag, last_tag)
|
||||||
|
|
||||||
|
last_tag_name = last_tag['name']
|
||||||
|
log = ''
|
||||||
|
prev_tag_time = self.get_time_of_tag(prev_tag)
|
||||||
|
pull_requests = self.get_all_closed_pull_requests
|
||||||
|
|
||||||
|
pull_requests.delete_if { |req|
|
||||||
|
t = Time.parse(req[:closed_at]).utc
|
||||||
|
t < prev_tag_time
|
||||||
|
}
|
||||||
|
|
||||||
|
log += "## [#{last_tag_name}] (https://github.com/#{$github_user}/#{$github_repo_name}/tree/#{last_tag_name})\n"
|
||||||
|
|
||||||
|
time_string = prev_tag_time.strftime "%Y/%m/%d"
|
||||||
|
log += "#### #{time_string}\n"
|
||||||
|
|
||||||
|
pull_requests.each { |dict|
|
||||||
|
merge = "#{dict[:title]} ([\\##{dict[:number]}](https://github.com/#{$github_user}/#{$github_repo_name}/pull/#{dict[:number]}))\n"
|
||||||
|
log += "- #{merge}"
|
||||||
|
}
|
||||||
|
|
||||||
|
log
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_time_of_tag(prev_tag)
|
||||||
|
github_git_data_commits_get = @github.git_data.commits.get $github_user, $github_repo_name, prev_tag['commit']['sha']
|
||||||
|
self.print_json github_git_data_commits_get.body
|
||||||
|
time_string = github_git_data_commits_get['committer']['date']
|
||||||
|
Time.parse(time_string)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -122,7 +127,7 @@ if __FILE__ == $0
|
||||||
|
|
||||||
log_generator = LogGenerator.new({:verbose => true})
|
log_generator = LogGenerator.new({:verbose => true})
|
||||||
|
|
||||||
tags = log_generator.get_all_tags
|
tags = log_generator.all_tags
|
||||||
p tags
|
|
||||||
|
|
||||||
|
log_generator.generate_log_between_tags(tags[1], tags[2])
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user