implement parser

This commit is contained in:
Petr Korolev 2014-11-05 13:27:28 +02:00
parent a52f961935
commit 392165ce0b
3 changed files with 61 additions and 8 deletions

View File

@ -2,12 +2,13 @@
# encoding: UTF-8 # encoding: UTF-8
require_relative 'log_generator' require_relative 'log_generator'
require_relative 'parser'
if __FILE__ == $0 def run_generator options
generator = LogGenerator.new generator = LogGenerator.new(options)
tag_time = generator.findPrevTagDate tag_time = generator.find_prev_tag_date
pull_requests = generator.getAllClosedPullRequests pull_requests = generator.get_all_closed_pull_requests
pull_requests.delete_if { |req| pull_requests.delete_if { |req|
t = Time.parse(req[:closed_at]).utc t = Time.parse(req[:closed_at]).utc
@ -15,4 +16,10 @@ if __FILE__ == $0
} }
generator.compund_changelog(tag_time, pull_requests) generator.compund_changelog(tag_time, pull_requests)
end
if __FILE__ == $0
options = Parser.new.options
run_generator(options)
end end

View File

@ -4,6 +4,12 @@ require 'json'
class LogGenerator class LogGenerator
attr_accessor :options
def initialize(options = {})
@options = options
end
def print_json(json) def print_json(json)
puts JSON.pretty_generate(json) puts JSON.pretty_generate(json)
end end
@ -13,7 +19,7 @@ class LogGenerator
%x[#{exec_cmd}] %x[#{exec_cmd}]
end end
def findPrevTagDate def find_prev_tag_date
value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag" value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag"
unless value1 unless value1
@ -30,13 +36,14 @@ class LogGenerator
exit exit
end end
puts "Prev tag is #{prev_tag}" if @options[:verbose]
puts "Prev tag is #{prev_tag}"
end
time = Time.parse(prev_tag) time = Time.parse(prev_tag)
end end
def getAllClosedPullRequests def get_all_closed_pull_requests
if $oauth_token if $oauth_token
github = Github.new oauth_token: $oauth_token github = Github.new oauth_token: $oauth_token

39
parser.rb Normal file
View 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