From 71970e1942f2b00f43ed92af4e7d65a113608359 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Fri, 24 Jul 2015 16:53:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=89=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=AE=B5=E6=9D=A5=E7=BB=9F=E8=AE=A1=E6=AF=8F=E4=BA=BA=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/repository/git.rb | 4 ++++ lib/redmine/scm/adapters/git_adapter.rb | 29 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index c1f0020eb..f3ea8e003 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -38,6 +38,10 @@ class Repository::Git < Repository 'Git' end + def commits(authors, start_date, end_date) + scm.commits(authors, start_date, end_date) + end + def report_last_commit extra_report_last_commit end diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index 1876190d9..81c361f6e 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -380,6 +380,35 @@ module Redmine nil end + def parse_commit(commits) + sum = {file: 0, insertion: 0, deletion: 0} + commits.split("\n").each do |commit| + if /(\d+)\s+?file/ =~ commit + sum[:file] += $1 .to_i + end + if /(\d+)\s+?insertion/ =~ commit + sum[:insertion] += $1.to_i + end + if /(\d+)\s+?deletion/ =~ commit + sum[:deletion] += $1.to_i + end + end + sum[:insertion] + sum[:deletion] + end + + def commits(authors, start_date, end_date) + rs = [] + authors.each do |author| + cmd_args = %W|log --pretty=tformat: --shortstat --author=#{author} --since=#{start_date} --until=#{end_date}| + commits = '' + git_cmd(cmd_args) do |io| + commits = io.read + end + rs << {author: author, num: parse_commit(commits)} + end + rs + end + class Revision < Redmine::Scm::Adapters::Revision # Returns the readable identifier def format_identifier