目的
gitリポジトリの更新行数を取得/レポーティングしたい
多数のプロジェクト/多数の人がいる環境で見やすくレポーティングしたい
取得できるレポート
メール件名
1 |
[Report] git update row count since YYYY-MM-DD |
メール本文
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
======== Summary ======== Total 1000 Line Updated ========= Description ========= - test1@test.com project1: 50 project2: 100 - test2@test.com project1: 100 project3: 1000 |
どのように取得しているか
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} && git log --author='#{author}' --since=#{since} --oneline --shortstat --no-merges 2>/dev/null | grep insertions | cut -d" " -f5 | awk 'BEGIN {sum=0} {sum+=$1} END {print sum}'</code>).to_i next if line == 0 result[" #{author}"]["#{project}"] = line total = total + line end } } pp result pp total Mail.defaults do delivery_method :smtp , { address: 'localhost' , port: 25 } end summary =<<" EOS " ======== Summary ======== Total #{total} Line Updated ========= Description ========= EOS result. each do |k, v| next if v.empty? summary = summary + << EOS - #{k} EOS v. each do |project, line| summary = summary + << EOS #{project}: #{line} EOS end summary = summary + "\n" end Mail.deliver do from 'git_report@test.com' to 'test@test.com' subject "[Report] git update row count since #{since}" body " #{summary}" end |