Class: Commit
- Inherits:
-
Object
- Object
- Commit
- Defined in:
- lib/commit.rb
Constant Summary collapse
- FILE_DIFF_REGEX =
/^diff --git a\/.* b\//
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#bug_id ⇒ Object
Returns the value of attribute bug_id.
-
#cached_files ⇒ Object
Returns the value of attribute cached_files.
-
#cached_trees ⇒ Object
Returns the value of attribute cached_trees.
-
#changes ⇒ Object
Returns the value of attribute changes.
-
#changes_total ⇒ Object
Returns the value of attribute changes_total.
-
#children ⇒ Object
Returns the value of attribute children.
-
#commit_id ⇒ Object
(also: #id)
Returns the value of attribute commit_id.
-
#date ⇒ Object
Returns the value of attribute date.
-
#deletions_total ⇒ Object
Returns the value of attribute deletions_total.
-
#file_diffs ⇒ Object
Returns the value of attribute file_diffs.
-
#insertions_total ⇒ Object
Returns the value of attribute insertions_total.
-
#issue_id ⇒ Object
Returns the value of attribute issue_id.
-
#movements ⇒ Object
Returns the value of attribute movements.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#trees ⇒ Object
Returns the value of attribute trees.
Class Method Summary collapse
- .from_git(commit_lines, git_client) ⇒ Object
- .parse_author(author) ⇒ Object
- .parse_commit(commit_lines, git_client) ⇒ Object
- .parse_commit_header(header) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
- #business_value ⇒ Object
-
#initialize(attrs = {}) ⇒ Commit
constructor
A new instance of Commit.
- #set_cached(tree) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Commit
Returns a new instance of Commit.
32 33 34 35 36 |
# File 'lib/commit.rb', line 32 def initialize(attrs={}) attrs.each do |key, val| instance_variable_set("@#{key}".to_sym, val) end end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
14 15 16 |
# File 'lib/commit.rb', line 14 def @author end |
#bug_id ⇒ Object
Returns the value of attribute bug_id.
27 28 29 |
# File 'lib/commit.rb', line 27 def bug_id @bug_id end |
#cached_files ⇒ Object
Returns the value of attribute cached_files.
24 25 26 |
# File 'lib/commit.rb', line 24 def cached_files @cached_files end |
#cached_trees ⇒ Object
Returns the value of attribute cached_trees.
25 26 27 |
# File 'lib/commit.rb', line 25 def cached_trees @cached_trees end |
#changes ⇒ Object
Returns the value of attribute changes.
20 21 22 |
# File 'lib/commit.rb', line 20 def changes @changes end |
#changes_total ⇒ Object
Returns the value of attribute changes_total.
23 24 25 |
# File 'lib/commit.rb', line 23 def changes_total @changes_total end |
#children ⇒ Object
Returns the value of attribute children.
13 14 15 |
# File 'lib/commit.rb', line 13 def children @children end |
#commit_id ⇒ Object Also known as: id
Returns the value of attribute commit_id.
12 13 14 |
# File 'lib/commit.rb', line 12 def commit_id @commit_id end |
#date ⇒ Object
Returns the value of attribute date.
15 16 17 |
# File 'lib/commit.rb', line 15 def date @date end |
#deletions_total ⇒ Object
Returns the value of attribute deletions_total.
22 23 24 |
# File 'lib/commit.rb', line 22 def deletions_total @deletions_total end |
#file_diffs ⇒ Object
Returns the value of attribute file_diffs.
18 19 20 |
# File 'lib/commit.rb', line 18 def file_diffs @file_diffs end |
#insertions_total ⇒ Object
Returns the value of attribute insertions_total.
21 22 23 |
# File 'lib/commit.rb', line 21 def insertions_total @insertions_total end |
#issue_id ⇒ Object
Returns the value of attribute issue_id.
26 27 28 |
# File 'lib/commit.rb', line 26 def issue_id @issue_id end |
#movements ⇒ Object
Returns the value of attribute movements.
19 20 21 |
# File 'lib/commit.rb', line 19 def movements @movements end |
#subject ⇒ Object
Returns the value of attribute subject.
16 17 18 |
# File 'lib/commit.rb', line 16 def subject @subject end |
#trees ⇒ Object
Returns the value of attribute trees.
17 18 19 |
# File 'lib/commit.rb', line 17 def trees @trees end |
Class Method Details
.from_git(commit_lines, git_client) ⇒ Object
67 68 69 |
# File 'lib/commit.rb', line 67 def from_git(commit_lines, git_client) Commit.new(parse_commit(commit_lines, git_client)) end |
.parse_author(author) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/commit.rb', line 132 def () = Iconv .conv("ascii//translit", "UTF-8", ) .tr("[]", "()") Mail::Address.new() end |
.parse_commit(commit_lines, git_client) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/commit.rb', line 71 def parse_commit(commit_lines, git_client) commit_id, , date, children, subject = parse_commit_header(commit_lines.shift()) Loggr.instance.info("PARSE COMMIT: #{commit_id}") if children.length > 1 commit_lines = git_client.diff(children.first, commit_id) end file_diffs = commit_lines .reduce([], &fold_reducer(FILE_DIFF_REGEX)) .map { |file_diff_lines| FileDiff.from_git(file_diff_lines) } insertions = file_diffs.reduce(0) { |sum, file_diff| sum + file_diff.insertions_total } deletions = file_diffs.reduce(0) { |sum, file_diff| sum + file_diff.deletions_total } file_diffs = file_diffs.reduce({}) do |obj, file_diff| obj[file_diff.b_file_name] = file_diff obj end if children.length > 1 diff_id = "#{children.first}..#{commit_id}" trees = git_client.parse_diff_tree(git_client.diff_tree(diff_id)) elsif children.length == 1 trees = git_client.parse_diff_tree(git_client.diff_tree(commit_id)) else trees = git_client.parse_ls_tree(git_client.ls_tree(commit_id)) end mutations = LineTracker.new.track_mutations!(file_diffs) { commit_id: commit_id, children: children, author: { name: .display_name, email: .address }, date: date, subject: subject, trees: trees, file_diffs: file_diffs, movements: mutations[:movements], changes: mutations[:changes], insertions_total: insertions, deletions_total: deletions, changes_total: insertions + deletions } end |
.parse_commit_header(header) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/commit.rb', line 120 def parse_commit_header(header) commit_id, children, , date, subject = header.split("|||") commit_id = commit_id.to_sym subject ||= "" children = children .split(" ") .map { |child_id| child_id.to_sym } = () date = DateTime.rfc2822(date) [commit_id, , date, children, subject] end |
Instance Method Details
#as_json ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/commit.rb', line 50 def as_json { commit_id: commit_id, children: children, author: , date: date, subject: subject, insertions_total: insertions_total, deletions_total: deletions_total, changes_total: changes.count, movements_total: movements.count, issue_id: issue_id, bug_id: bug_id } end |
#business_value ⇒ Object
43 44 45 46 47 48 |
# File 'lib/commit.rb', line 43 def business_value issue = ::Store::Issue[issue_id] issue.present? ? issue[:business_value] : 0 end |
#set_cached(tree) ⇒ Object
38 39 40 41 |
# File 'lib/commit.rb', line 38 def set_cached(tree) @cached_files = tree.select { |obj| obj[:type] == :file } @cached_trees = tree.select { |obj| obj[:type] == :tree } end |