gitlab_git 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb27fdbe97e58c0c68ac78da7daacdf65f255a38
4
- data.tar.gz: d2a1029af718f1fdfdac16c0269b8993c4a2a876
3
+ metadata.gz: e1c33717978708a9c7bfd0e2f85847cb558d94f0
4
+ data.tar.gz: 2604d9e922980d00bcc6b9dfae9a7def3493f0dc
5
5
  SHA512:
6
- metadata.gz: 69057ad30cad8f6460f3dc1c0004fc9a2c0fe04e0b700e0bd7f3e2d2498ca4c91f89d2f97b6803db244818268bdd21af7475b7417eeac8b3b27fc0290228e294
7
- data.tar.gz: 57c18ebb56693cc919b712e5d62547cf8b8a51e3a7734f18e4718e4137bbd507680faae2cabc05595283dc9e5ce8ced7bbad2a5cf93bd0794bc0ae534bff89bd
6
+ metadata.gz: ac05b8e0f12b2d1591e753d1b0587c2d5da95593c67e16a1afda31c8f00ddc9e07dc42c41607fb5248eaa75e35b5f9f7a3d7d0e147272a0c99e81a0323ac613d
7
+ data.tar.gz: 8a73a2d71cce28ccca47274a4c8a3d5aaa3c28ec3b52efa4daa78029d2abf1b27fca6a3b8f2ab1dea00d8febd810b19ca1f48fd86095ae31d2bd885259ca1d76
data/lib/gitlab_git.rb CHANGED
@@ -22,3 +22,5 @@ require_relative "gitlab_git/repository"
22
22
  require_relative "gitlab_git/stats"
23
23
  require_relative "gitlab_git/tree"
24
24
  require_relative "gitlab_git/blob_snippet"
25
+ require_relative "gitlab_git/git_stats"
26
+ require_relative "gitlab_git/log_parser"
@@ -4,10 +4,14 @@
4
4
  module Gitlab
5
5
  module Git
6
6
  class Commit
7
- attr_accessor :raw_commit, :head, :refs,
8
- :id, :authored_date, :committed_date, :message,
9
- :author_name, :author_email, :parent_ids,
10
- :committer_name, :committer_email
7
+ attr_accessor :raw_commit, :head, :refs
8
+
9
+ SERIALIZE_KEYS = [
10
+ :id, :message, :parent_ids,
11
+ :authored_date, :author_name, :author_email,
12
+ :committed_date, :committer_name, :committer_email
13
+ ]
14
+ attr_accessor *SERIALIZE_KEYS
11
15
 
12
16
  def initialize(raw_commit, head = nil)
13
17
  raise "Nil as raw commit passed" unless raw_commit
@@ -21,10 +25,6 @@ module Gitlab
21
25
  @head = head
22
26
  end
23
27
 
24
- def serialize_keys
25
- @serialize_keys ||= %w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids).map(&:to_sym)
26
- end
27
-
28
28
  def sha
29
29
  id
30
30
  end
@@ -78,15 +78,9 @@ module Gitlab
78
78
  end
79
79
 
80
80
  def to_hash
81
- hash = {}
82
-
83
- keys = serialize_keys
84
-
85
- keys.each do |key|
81
+ serialize_keys.map.with_object({}) do |key, hash|
86
82
  hash[key] = send(key)
87
83
  end
88
-
89
- hash
90
84
  end
91
85
 
92
86
  def date
@@ -132,9 +126,13 @@ module Gitlab
132
126
  raw_commit = hash.symbolize_keys
133
127
 
134
128
  serialize_keys.each do |key|
135
- send(:"#{key}=", raw_commit[key.to_sym])
129
+ send("#{key}=", raw_commit[key])
136
130
  end
137
131
  end
132
+
133
+ def serialize_keys
134
+ SERIALIZE_KEYS
135
+ end
138
136
  end
139
137
  end
140
138
  end
@@ -0,0 +1,24 @@
1
+ require_relative 'log_parser'
2
+
3
+ module Gitlab
4
+ module Git
5
+ class GitStats
6
+ attr_accessor :repo, :ref
7
+
8
+ def initialize repo, ref
9
+ @repo, @ref = repo, ref
10
+ end
11
+
12
+ def log
13
+ args = ['--format=%aN%x0a%ad', '--date=short', '--shortstat', '--no-merges']
14
+ repo.git.run(nil, 'log', nil, {}, args)
15
+ rescue Grit::Git::GitTimeout
16
+ nil
17
+ end
18
+
19
+ def parsed_log
20
+ LogParser.parse_log(log)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ module Gitlab
2
+ module Git
3
+ class LogParser
4
+ # Parses the log file into a collection of commits
5
+ # Data model: {author, date, additions, deletions}
6
+ def self.parse_log log_from_git
7
+ log = log_from_git.split("\n")
8
+
9
+ i = 0
10
+ collection = []
11
+ entry = {}
12
+
13
+ while i <= log.size do
14
+ pos = i % 4
15
+ case pos
16
+ when 0
17
+ unless i == 0
18
+ collection.push(entry)
19
+ entry = {}
20
+ end
21
+ entry[:author] = log[i].to_s
22
+ when 1
23
+ entry[:date] = log[i].to_s
24
+ when 3
25
+ changes = log[i].split(",")
26
+ entry[:additions] = changes[1].to_i unless changes[1].nil?
27
+ entry[:deletions] = changes[2].to_i unless changes[2].nil?
28
+ end
29
+ i += 1
30
+ end
31
+
32
+ collection
33
+ end
34
+ end
35
+ end
36
+ end
@@ -111,7 +111,7 @@ module Gitlab
111
111
 
112
112
  # Returns an Array of tag names
113
113
  def tag_names
114
- repo.tags.collect(&:name).sort.reverse
114
+ tags.map(&:name)
115
115
  end
116
116
 
117
117
  # Returns an Array of Tags
@@ -121,7 +121,7 @@ module Gitlab
121
121
 
122
122
  # Returns an Array of branch and tag names
123
123
  def ref_names
124
- [branch_names + tag_names].flatten
124
+ branch_names + tag_names
125
125
  end
126
126
 
127
127
  def heads
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Zaporozhets
@@ -65,6 +65,8 @@ files:
65
65
  - lib/gitlab_git/commit.rb
66
66
  - lib/gitlab_git/compare.rb
67
67
  - lib/gitlab_git/diff.rb
68
+ - lib/gitlab_git/git_stats.rb
69
+ - lib/gitlab_git/log_parser.rb
68
70
  - lib/gitlab_git/popen.rb
69
71
  - lib/gitlab_git/repository.rb
70
72
  - lib/gitlab_git/stats.rb