程序猿的一天,早晨上班开站会,讨论项目需求和进度,澄清当天的工作任务,结束站会就开始敲代码,天昏地暗脑细胞少了很多  %$&){*!^$。。。

就这样还总被领导怀疑开发能力不够,存在感不足,非常气愤、非常的不爽,通过 Jenkins 来统计一下代码提交量,看看个人的贡献度有多高。

下面就在创建好的工程里,只需要增加两个构建步骤,就实现不同的工具进行代码量统计了,如下代码片段截图:

Jenkins 统计研发人员的代码提交量_cloc

脚本配置好,即可执行编译,项目顺利编译完成后,项目也打包发布完成,代码量也统计好了。

下面看看不同的工具代码统计结果吧。

通过 cloc 工具统计如下:

Jenkins 统计研发人员的代码提交量_git_02

通过脚本工具统计如下:

Jenkins 统计研发人员的代码提交量_cloc_03

通过 GitStats工具统计如下:

Jenkins 统计研发人员的代码提交量_cloc_04

更新统计 20200708

###################################################################################################

还一个跟 gitstats 功能差不多的小工具  gitinspector  也能统计数据,但统计分析数据个人感觉,没有 gitstats 直观全面,下面可以看看效果。

Jenkins 统计研发人员的代码提交量_git_05

$ ​python gitinspector.py​ ​--format=html --timeline --localize-output -wTHL​ /scm/Demo> /scm/Demo/test.html

###################################################################################################


Jenkins 统计研发人员的代码提交量_gitstats_06

#########################################################################################################

#!/bin/bash

echo $workspace

ymd=`date +%Y-%m-%d`

if [ -z $begin_time ];then

   echo "begin time is null,cat not begin statistics"

   exit

fi

if [ -z $end_time ];then

    echo "end time is today"

    end_time=$ymd

fi

project_name=($project_name)

echo $project_name

[ -d code_file ]&& rm -rf code_file

[ -f commit.log ]&& rm -rf commit.log

for code_project_name in ${project_name[@]}

do

echo "project is $code_project_name" >> commit.log

#begin sync $code_project_name code

git clone ssh://git@110.139.139.118:2020/$group_name/$project_name.git -b ${branch_name} code_file

if [ $? -ne 0 ]; then

    echo "sync code fail"

    exit

else

    echo "sync code success"

fi

cd code_file

ymd=`date +%Y%m%d_%H:%M:%S`;

/usr/bin/cloc . >> ../commit.log

git log --format='%aN' --after="$begin_time" --before="$end_time" | sort -u | while read name; do echo -en "$name\t";git log --after="$begin_time" --before="$end_time" --author="$name" --pretty=tformat: --numstat |  grep -v vendor | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "%s, %s, %s\n", add, subs, loc }' -; done >> ../commit.log

if [ $? -ne 0 ]; then

    echo " code fail"

    exit

else

    echo "Code_Statistics success"

fi

cd -

done

cat commit.log

#########################################################################################################

不知道程序猿们看了有啥想法呢?