Class: Wlog::GitCommitParser

Inherits:
Object
  • Object
show all
Defined in:
lib/wlog/tech/git_commit_parser.rb

Overview

Author:

  • Simon Symeonidis

Class Method Summary collapse

Class Method Details

.parse(log_s) ⇒ Object

Returns a list of GitCommit objects.

Parameters:

  • log_s

    is the string obtained from running a ‘git log` command

Returns:

  • a list of GitCommit objects



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wlog/tech/git_commit_parser.rb', line 8

def self.parse(log_s)
  cur = nil 
  inmessage = false 
  gitlogs = [] 
   
  log_s.lines.each do |line| 
    case line
    when /^commit/i
      inmessage = false 
      gitlogs.push cur if cur
      cur = GitCommit.new
      cur.commit = line.split[1].strip
                          
    when /^author/i
      next unless cur
      cur.author = line.split[1].strip
                                 
    when /^date/i, /^\n$/
      next
                                        
    else 
      next unless cur
      if inmessage
        cur.message.concat(line)
        cur.message.strip!
      else
        cur.shortlog = line
        cur.shortlog.strip! 
        inmessage = true
      end 
    end
  
  end
  
  # if commits have no hash, discard them
  gitlogs.reject! { |e| e.commit == "" }
  gitlogs.push cur if cur
gitlogs end