module GitLogToJson
Constants
- VERSION
Public Class Methods
print_json(dir, option)
click to toggle source
# File lib/git_log_to_json.rb, line 22 def self.print_json(dir, option) Dir.chdir(dir) do format_opts = ['%H', '%an', '%ad', '%s'] format = format_opts.join('%x0b') + '%x07' cmd_base = 'git log ' cmd_opts = '' if option[:number] cmd_opts += "-n #{option[:number]} " end cmd_opts += "--pretty=format:\"#{format}\"" cmd = cmd_base + cmd_opts git_log = `#{cmd}` ary = [] keys = [:hash, :author_name, :author_date, :subject] git_log.split("\a").each do |line| h = {} values = line.split("\v") values[0].gsub!(/\n/, '') raise Exception.new('size error') if values.size != 4 begin tr = [keys, values].transpose h = Hash[*tr.flatten] ary.push(h) rescue => e puts e end end puts ary.to_json end end
version()
click to toggle source
# File lib/git_log_to_json.rb, line 18 def self.version puts GitLogToJson::VERSION end