公司绩效考核要求,统计GITLAB仓库全部人提示有效代码行业git
脚本1: 统计全部仓库、全部提交人的代码总行数(新增长-删除) 脚本2: 统计全部仓库、全部提交人的代码提交汇总与删除汇总 脚本3: 统计指定仓库的全部提交人的代码提交 汇总与删除汇总数组
注意:全部代码行数为0,统计结果中清除。 全部统计只统计master分支。bash
安装: 把脚本中的仓库路径搜索修改成GitLab的存储目录。 统计结果存储在/home目录下面。gitlab
[root@gitlab home]# cat code_statistics.sh
#!/bin/bash
master_dev='master'
date_star='2018-11-01'
date_end='2018-11-30'
path1=`find /home/gitlab_data/ -name "*.git"`
echo '' > /home/total.txt
#echo $path1
##arr=($a)用于将字符串$a分割到数组$arr ${arr[0]} ${arr[1]} ... 分别存储分割后的数组第1 2 ... 项 ,${arr[@]}存储整个数组。变量$IFS存储着分隔符,这里咱们将其设为逗号 "," OLD_IFS用于备份默认的分隔符,使用完后将之恢复默认。
OLD_IFS="$IFS"
IFS=" "
arr=($path1)
IFS="$OLD_IFS"
for s in ${arr[@]}
do code
#echo "$s"
cd $s
user1=`git log --pretty='%aN' | sort | uniq `
OLD_IFS="$IFS1"
IFS1=" "
arr1=($user1)
IFS="$OLD_IFS1"
for s1 in ${arr1[@]}
doorm
#echo "$s1" 字符串
# if [[ $s1 != *HEAD* ]]
# then
total=`git log $master_dev --since ==$date_star --until=$date_end --author=$s1 --pretty=tformat: --numstat | awk '{ loc += $1 -$2 } END { printf loc }'`
#total_temp1=`git log $master_dev --since ==$date_star --until=$date_end --author='$s1' --pretty=tformat: --numstat | awk '{ printf $1}'`
#echo $total_temp1
# echo '' > /home/total.txt
#if [ -n "$total" ];
#then
echo $s1 $total >> /home/total.txt
#fi
# fi
#user1=`git log --pretty='%aN' | sort | uniq `it
doneast
doneform
cat /home/total.txt | awk '{a[$1]+=$2}END{for(i in a)print i,a[i]}' > /home/total_end.txtcat /home/total_end.txt |grep -v '\ 0' > /home/total_all.txt