summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKarlo Soriano <dev+karlo@aelogica.com>2013-05-09 13:00:56 +0800
committerkarlo57 <karlo.karlo.karlo@gmail.com>2013-06-05 16:51:48 +0800
commit71d67e6557acb1ce3beeec2c2c6deb35015bd8bb (patch)
treec8e23f80ee62359d8db8574056ea69ac70eb4406 /lib
parentb9d989dc056a2a2b9316ff9aa06b57c736426871 (diff)
downloadgitlab-ce-71d67e6557acb1ce3beeec2c2c6deb35015bd8bb.tar.gz
Contributors graphs feature for GitLab
Created tests and refactored some code along the way Added stat graph util spec, refactored code finsihed up tests and refactors finsihed up tests and refactors
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git_stats.rb20
-rw-r--r--lib/gitlab/git_stats_log_parser.rb32
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/gitlab/git_stats.rb b/lib/gitlab/git_stats.rb
new file mode 100644
index 00000000000..1f303f6de64
--- /dev/null
+++ b/lib/gitlab/git_stats.rb
@@ -0,0 +1,20 @@
+require 'gitlab/git_stats_log_parser'
+
+module Gitlab
+ class GitStats
+ attr_accessor :repo, :ref
+
+ def initialize repo, ref
+ @repo, @ref = repo, ref
+ end
+
+ def log
+ args = ['--format=%aN%x0a%ad', '--date=short', '--shortstat', '--no-merges']
+ repo.git.run(nil, 'log', nil, {}, args)
+ end
+
+ def parsed_log
+ LogParser.parse_log(log)
+ end
+ end
+end
diff --git a/lib/gitlab/git_stats_log_parser.rb b/lib/gitlab/git_stats_log_parser.rb
new file mode 100644
index 00000000000..784e08c27b9
--- /dev/null
+++ b/lib/gitlab/git_stats_log_parser.rb
@@ -0,0 +1,32 @@
+class LogParser
+ #Parses the log file into a collection of commits
+ #Data model: {author, date, additions, deletions}
+ def self.parse_log log_from_git
+ log = log_from_git.split("\n")
+
+ i = 0
+ collection = []
+ entry = {}
+
+ while i <= log.size do
+ pos = i % 4
+ case pos
+ when 0
+ unless i == 0
+ collection.push(entry)
+ entry = {}
+ end
+ entry[:author] = log[i].to_s
+ when 1
+ entry[:date] = log[i].to_s
+ when 3
+ changes = log[i].split(",")
+ entry[:additions] = changes[1].to_i unless changes[1].nil?
+ entry[:deletions] = changes[2].to_i unless changes[2].nil?
+ end
+ i += 1
+ end
+
+ collection
+ end
+end \ No newline at end of file