2014-11-03 11:57:10 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# encoding: UTF-8
|
|
|
|
|
|
|
|
require 'github_api'
|
|
|
|
require 'json'
|
2014-11-04 15:28:39 +00:00
|
|
|
require_relative 'constants'
|
2014-11-03 11:57:10 +00:00
|
|
|
|
|
|
|
def print_json(json)
|
|
|
|
puts JSON.pretty_generate(json)
|
|
|
|
end
|
|
|
|
|
|
|
|
def exec_command(cmd)
|
|
|
|
%x[cd #{@project_path} && #{cmd}]
|
|
|
|
end
|
|
|
|
|
2014-11-04 14:52:28 +00:00
|
|
|
def findPrevTagDate
|
|
|
|
|
2014-11-04 15:28:39 +00:00
|
|
|
value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag"
|
2014-11-03 11:57:10 +00:00
|
|
|
unless value1
|
|
|
|
puts 'not found this tag'
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2014-11-04 15:28:39 +00:00
|
|
|
scan_results = value1.scan(/.*tag.*/)
|
2014-11-04 14:52:28 +00:00
|
|
|
|
|
|
|
prev_tag = scan_results[1]
|
2014-11-03 11:57:10 +00:00
|
|
|
|
2014-11-04 14:52:28 +00:00
|
|
|
unless scan_results.count
|
2014-11-03 11:57:10 +00:00
|
|
|
puts 'Not found any versions'
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2014-11-04 14:52:28 +00:00
|
|
|
puts "Prev tag is #{prev_tag}"
|
|
|
|
|
|
|
|
time = Time.parse(prev_tag)
|
2014-11-03 11:57:10 +00:00
|
|
|
end
|
|
|
|
|
2014-11-04 14:52:28 +00:00
|
|
|
|
2014-11-03 11:57:10 +00:00
|
|
|
def getAllClosedPullRequests
|
|
|
|
|
2014-11-04 15:32:07 +00:00
|
|
|
if @oauth_token
|
2014-11-04 15:28:39 +00:00
|
|
|
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
|
2014-11-03 11:57:10 +00:00
|
|
|
|
2014-11-04 15:28:39 +00:00
|
|
|
json.each { |dict|
|
|
|
|
# print_json dict
|
|
|
|
# puts "##{dict[:number]} - #{dict[:title]} (#{dict[:closed_at]})"
|
|
|
|
}
|
|
|
|
|
|
|
|
json
|
2014-11-03 11:57:10 +00:00
|
|
|
|
2014-11-04 15:28:39 +00:00
|
|
|
end
|
2014-11-03 15:22:29 +00:00
|
|
|
|
2014-11-04 15:28:39 +00:00
|
|
|
def compund_changelog(tag_time, pull_requests)
|
2014-11-03 15:22:29 +00:00
|
|
|
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"
|
2014-11-04 14:52:28 +00:00
|
|
|
|
2014-11-03 15:22:29 +00:00
|
|
|
time_string = tag_time.strftime "%Y/%m/%d"
|
|
|
|
log += "#### #{time_string}\n"
|
|
|
|
|
|
|
|
pull_requests.each { |dict|
|
2014-11-04 14:52:28 +00:00
|
|
|
merge = "#{dict[:title]} ([\\##{dict[:number]}](https://github.com/#{@github_user}/#{@github_repo_name}/pull/#{dict[:number]}))\n"
|
2014-11-04 15:28:39 +00:00
|
|
|
log += "- #{merge}"
|
2014-11-03 15:22:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
puts log
|
|
|
|
File.open('output.txt', 'w') { |file| file.write(log) }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-11-04 14:52:28 +00:00
|
|
|
tag_time = findPrevTagDate
|
2014-11-03 11:57:10 +00:00
|
|
|
|
|
|
|
pull_requests = getAllClosedPullRequests
|
|
|
|
|
|
|
|
pull_requests.delete_if { |req|
|
|
|
|
t = Time.parse(req[:closed_at]).utc
|
|
|
|
t < tag_time
|
|
|
|
}
|
|
|
|
|
2014-11-04 15:28:39 +00:00
|
|
|
compund_changelog tag_time, pull_requests
|