implement parser
This commit is contained in:
parent
a52f961935
commit
392165ce0b
|
@ -2,12 +2,13 @@
|
|||
# encoding: UTF-8
|
||||
|
||||
require_relative 'log_generator'
|
||||
require_relative 'parser'
|
||||
|
||||
if __FILE__ == $0
|
||||
generator = LogGenerator.new
|
||||
def run_generator options
|
||||
generator = LogGenerator.new(options)
|
||||
|
||||
tag_time = generator.findPrevTagDate
|
||||
pull_requests = generator.getAllClosedPullRequests
|
||||
tag_time = generator.find_prev_tag_date
|
||||
pull_requests = generator.get_all_closed_pull_requests
|
||||
|
||||
pull_requests.delete_if { |req|
|
||||
t = Time.parse(req[:closed_at]).utc
|
||||
|
@ -16,3 +17,9 @@ if __FILE__ == $0
|
|||
|
||||
generator.compund_changelog(tag_time, pull_requests)
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
|
||||
options = Parser.new.options
|
||||
run_generator(options)
|
||||
end
|
|
@ -4,6 +4,12 @@ require 'json'
|
|||
|
||||
class LogGenerator
|
||||
|
||||
attr_accessor :options
|
||||
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
end
|
||||
|
||||
def print_json(json)
|
||||
puts JSON.pretty_generate(json)
|
||||
end
|
||||
|
@ -13,7 +19,7 @@ class LogGenerator
|
|||
%x[#{exec_cmd}]
|
||||
end
|
||||
|
||||
def findPrevTagDate
|
||||
def find_prev_tag_date
|
||||
|
||||
value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag"
|
||||
unless value1
|
||||
|
@ -30,13 +36,14 @@ class LogGenerator
|
|||
exit
|
||||
end
|
||||
|
||||
puts "Prev tag is #{prev_tag}"
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Prev tag is #{prev_tag}"
|
||||
end
|
||||
time = Time.parse(prev_tag)
|
||||
end
|
||||
|
||||
|
||||
def getAllClosedPullRequests
|
||||
def get_all_closed_pull_requests
|
||||
|
||||
if $oauth_token
|
||||
github = Github.new oauth_token: $oauth_token
|
||||
|
|
39
parser.rb
Normal file
39
parser.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require 'optparse'
|
||||
class Parser
|
||||
|
||||
# attr_accessor
|
||||
attr_reader :options
|
||||
|
||||
def initialize
|
||||
@options = {:tag1 => nil, :tag2 => nil}
|
||||
|
||||
parser = OptionParser.new { |opts|
|
||||
opts.banner = 'Usage: changelog_generator.rb [tag1 tag2] [options]'
|
||||
|
||||
opts.on('-h', '--help', 'Displays Help') do
|
||||
puts opts
|
||||
exit
|
||||
end
|
||||
|
||||
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
||||
@options[:verbose] = v
|
||||
end
|
||||
}
|
||||
|
||||
parser.parse!
|
||||
|
||||
#udefined case with 1 parameter:
|
||||
if ARGV[0] && !ARGV[1]
|
||||
puts parser.banner
|
||||
exit
|
||||
end
|
||||
|
||||
if ARGV[1]
|
||||
@options[:tag1] = ARGV[0]
|
||||
@options[:tag2] = ARGV[1]
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user