Module: GitLogToJson

Defined in:
lib/git_log_to_json.rb,
lib/git_log_to_json/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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

.versionObject



18
19
20
# File 'lib/git_log_to_json.rb', line 18

def self.version
  puts GitLogToJson::VERSION
end