-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_parser.rb
61 lines (51 loc) · 1.62 KB
/
git_parser.rb
1
2
3
4
5
6
7
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'rubygems'
require 'json'
require_relative 'parse_mingle_info'
class GitParser
def self.files_map
files_mapping = {}
commit_chunks.each do |chunk|
commit_metadata, raw_all_files = chunk.split('######')
raw_all_files.split.select{|file| file.include?('app/')}.each do |file|
file_info = files_mapping[file] || FileInfo.new(file)
file_info.raw_commit = commit_metadata
files_mapping[file] = file_info
end
end
files_mapping
end
def self.commit_chunks
project_directory = YAML.load_file('properties.yml')['project_directory']
raw_commits = `git --git-dir #{project_directory}/.git log --format='&&&&&%h^^^%ci^^^%s%######' --name-only`
commit_chunks = raw_commits.split('&&&&&')
commit_chunks[1..-1]
end
end
class FileInfo
attr_accessor :file_name, :raw_commits, :bug_count, :change_count, :card_numbers
@@mingle_info = ParseMingleInfo.new
def initialize(file_name)
@file_name = file_name
@raw_commits = []
@card_numbers = []
@bug_count=0
@change_count=0
end
def raw_commit=(commit)
self.raw_commits << commit
process_commit
end
private
def process_commit
number = self.raw_commits.last.match(/.#(?<number>[0-9]*)/)
self.card_numbers << number.nil? ? nil : self.raw_commits.last.match(/.#(?<number>[0-9]*)/)["number"]
increment_count @@mingle_info.type(card_numbers.last)
end
def increment_count(type)
if (!type.nil? && type == "Defect") || raw_commits.last.downcase.include?('fix') || raw_commits.last.downcase.include?('bug')
self.bug_count = self.bug_count + 1
else
self.change_count = self.change_count + 1
end
end
end