gitリポジトリの追加行数レポーティング (gitlab)

目的

gitリポジトリの更新行数を取得/レポーティングしたい
多数のプロジェクト/多数の人がいる環境で見やすくレポーティングしたい

取得できるレポート

メール件名

メール本文

どのように取得しているか

git logコマンドを利用して取得します。

リポジトリディレクトリに移動しgit logコマンドを打つ

下記コマンドで対象レポジトリへの更新行数を日付指定で求める事ができます。

1
2
3
4
5
# pwd
/home/git/repositories/skyarchnetworks/linuxscripts.git
# git log --author='test@test.com' --since=2014-07-01 --oneline --shortstat --no-merges 2>/dev/null
533ecf8 Feature:  fix exit code to 2  and print message
 2 files changed, 59 insertions(+), 16 deletions(-)

下記スクリプト中では追加行数のみをカウントしております。
このため、フレームワークを利用する新規プロジェクトが追加されると大変な行数が追加されレポートが
あまり使い物にならないため、あくまでも既存プロジェクトの進捗目安としたほうが良いと思います。

実際に動作させているスクリプト

member 配列を順次author に入れて回しています。
その際に gitlabが作成する .wiki.git ディレクトリは無視するようにしています。

注意点としてはgit pushする際のauthor 名がそのままレポジトリ上に反映されていますので
統一する必要があります。
(gitlab だとユーザ名/メールアドレスどちらでも受け付けてくれるため。)

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
62
63
64
65
66
67
68
69
#!/usr/bin/ruby
 
require 'rubygems'
require 'active_support/all'
require 'mail'
require 'pp'
 
members = [
  'test1@test.com',
  'test2@test.com'
]
result = {}
total = 0
since = Time.now.last_month.strftime("%Y-%m-25")
 
Dir::chdir('/home/git/repositories')
git_repo_path = Dir.glob('*/*')
members.each {|author|
    result["#{author}"] = {}
    git_repo_path.each {|dir|
        if /\.wiki/ !~ dir
            project = dir.gsub(/.*\/(.*)\.git/, '\1')
            line = (<code>cd #{dir} &amp;&amp; git log --author='#{author}' --since=#{since} --oneline --shortstat --no-merges 2&gt;/dev/null | grep insertions | cut -d&quot; &quot; -f5 | awk 'BEGIN {sum=0} {sum+=$1} END {print sum}'</code>).to_i
            next if line == 0
            result[&quot;#{author}&quot;][&quot;#{project}&quot;] = line
            total = total + line
        end
    }
}
pp result
pp total
 
Mail.defaults do
  delivery_method :smtp, { address: 'localhost', port: 25 }
end
 
summary =&lt;&lt;&quot;EOS&quot;
========
Summary
========
 
Total #{total} Line Updated
 
=========
Description
=========
 
EOS
 
 
result.each do |k, v|
  next if v.empty?
  summary = summary + &lt;&lt;EOS
- #{k}
EOS
  v.each do |project, line|
summary = summary + &lt;&lt;EOS
  #{project}: #{line}
EOS
  end
  summary = summary + &quot;\n&quot;
end
 
Mail.deliver do
  from    'git_report@test.com'
  to      'test@test.com'
  subject &quot;[Report] git update row count since #{since}&quot;
  body    &quot;#{summary}&quot;
end

投稿者プロフィール

takashi
Japan AWS Ambassadors 2023, 2024
開発会社での ASP型WEBサービス企画 / 開発 / サーバ運用 を経て
2010年よりスカイアーチネットワークスに在籍しております

機械化/効率化/システム構築を軸に人に喜んで頂ける物作りが大好きです。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


Time limit is exhausted. Please reload CAPTCHA.