Class: Gitlab::Git::LogParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_git/log_parser.rb

Class Method Summary collapse

Class Method Details

.parse_log(log_from_git) ⇒ Object

Parses the log file into a collection of commits Data model:

{author_name, author_email, date, additions, deletions}


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab_git/log_parser.rb', line 7

def self.parse_log(log_from_git)
  log = log_from_git.split("\n")
  collection = []

  log.each_slice(5) do |slice|
    entry = {}
    entry[:author_name] = slice[0].force_encoding('UTF-8')
    entry[:author_email] = slice[1].force_encoding('UTF-8')
    entry[:date] = slice[2]

    if slice[4]
      changes = slice[4]

      entry[:additions] = $1.to_i if changes =~ /(\d+) insertion/
      entry[:deletions] = $1.to_i if changes =~ /(\d+) deletion/
    end

    collection.push(entry)
  end

  collection
end