move all methods in separate class
This commit is contained in:
parent
60c070c230
commit
b3dfa00ec5
|
@ -1,85 +1,16 @@
|
|||
#!/usr/bin/env ruby
|
||||
# encoding: UTF-8
|
||||
|
||||
require 'github_api'
|
||||
require 'json'
|
||||
require_relative 'constants'
|
||||
require_relative 'log_generator'
|
||||
|
||||
def print_json(json)
|
||||
puts JSON.pretty_generate(json)
|
||||
end
|
||||
generator = LogGenerator.new
|
||||
|
||||
def exec_command(cmd)
|
||||
%x[cd #{@project_path} && #{cmd}]
|
||||
end
|
||||
|
||||
def findPrevTagDate
|
||||
|
||||
value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag"
|
||||
unless value1
|
||||
puts 'not found this tag'
|
||||
exit
|
||||
end
|
||||
|
||||
scan_results = value1.scan(/.*tag.*/)
|
||||
|
||||
prev_tag = scan_results[1]
|
||||
|
||||
unless scan_results.count
|
||||
puts 'Not found any versions'
|
||||
exit
|
||||
end
|
||||
|
||||
puts "Prev tag is #{prev_tag}"
|
||||
|
||||
time = Time.parse(prev_tag)
|
||||
end
|
||||
|
||||
|
||||
def getAllClosedPullRequests
|
||||
|
||||
if @oauth_token
|
||||
github = Github.new oauth_token: @oauth_token
|
||||
else
|
||||
github = Github.new
|
||||
end
|
||||
issues = github.pull_requests.list @github_user, @github_repo_name, :state => 'closed'
|
||||
json = issues.body
|
||||
|
||||
json.each { |dict|
|
||||
# print_json dict
|
||||
# puts "##{dict[:number]} - #{dict[:title]} (#{dict[:closed_at]})"
|
||||
}
|
||||
|
||||
json
|
||||
|
||||
end
|
||||
|
||||
def compund_changelog(tag_time, pull_requests)
|
||||
log = ''
|
||||
last_tag = exec_command('git describe --abbrev=0 --tags').strip
|
||||
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}"
|
||||
}
|
||||
|
||||
puts log
|
||||
File.open('output.txt', 'w') { |file| file.write(log) }
|
||||
|
||||
end
|
||||
|
||||
tag_time = findPrevTagDate
|
||||
|
||||
pull_requests = getAllClosedPullRequests
|
||||
tag_time = generator.findPrevTagDate
|
||||
pull_requests = generator.getAllClosedPullRequests
|
||||
|
||||
pull_requests.delete_if { |req|
|
||||
t = Time.parse(req[:closed_at]).utc
|
||||
t < tag_time
|
||||
}
|
||||
|
||||
compund_changelog tag_time, pull_requests
|
||||
generator.compund_changelog(tag_time, pull_requests)
|
|
@ -1,3 +1,76 @@
|
|||
require_relative 'constants'
|
||||
require 'github_api'
|
||||
require 'json'
|
||||
|
||||
class LogGenerator
|
||||
|
||||
def print_json(json)
|
||||
puts JSON.pretty_generate(json)
|
||||
end
|
||||
|
||||
def exec_command(cmd)
|
||||
exec_cmd = "cd #{$project_path} && #{cmd}"
|
||||
%x[#{exec_cmd}]
|
||||
end
|
||||
|
||||
def findPrevTagDate
|
||||
|
||||
value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag"
|
||||
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
|
||||
|
||||
puts "Prev tag is #{prev_tag}"
|
||||
|
||||
time = Time.parse(prev_tag)
|
||||
end
|
||||
|
||||
|
||||
def getAllClosedPullRequests
|
||||
|
||||
if $oauth_token
|
||||
github = Github.new oauth_token: $oauth_token
|
||||
else
|
||||
github = Github.new
|
||||
end
|
||||
issues = github.pull_requests.list $github_user, $github_repo_name, :state => 'closed'
|
||||
json = issues.body
|
||||
|
||||
json.each { |dict|
|
||||
# print_json dict
|
||||
# puts "##{dict[:number]} - #{dict[:title]} (#{dict[:closed_at]})"
|
||||
}
|
||||
|
||||
json
|
||||
|
||||
end
|
||||
|
||||
def compund_changelog(tag_time, pull_requests)
|
||||
log = ''
|
||||
last_tag = exec_command('git describe --abbrev=0 --tags').strip
|
||||
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}"
|
||||
}
|
||||
|
||||
puts log
|
||||
File.open('output.txt', 'w') { |file| file.write(log) }
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user