统计Git

公司需求统计Mos代码行数

方法一:用git

#!/bin/bash

read -p "输入你要统计mos的分支:" branch

Mos_Project=(uusafe-prod-mos-app-inte uusafe-prod-mos-app-client uusafe-prod-mos-app-service uusafe-prod-mos-app-rest uusafe-prod-mos-base-inte uusafe-prod-mos-base-client uusafe-prod-mos-base-rest uusafe-prod-mos-base-service  uusafe-prod-mos-device-inte uusafe-prod-mos-device-client uusafe-prod-mos-device-rest uusafe-prod-mos-device-service uusafe-prod-mos-wrapping-inte  uusafe-prod-mos-wrapping-rest uusafe-prod-mos-wrapping-service uusafe-prod-mos-wrapping-client uusafe-prod-mos-gateway-inte uusafe-prod-mos-gateway-client uusafe-prod-mos-gateway-rest uusafe-prod-mos-gateway-service)
Users=(填写开发人员的git账号)

Since_Today=`date +%F --date="-3 month"`
Until_Today=`date +%F`
echo -e "\033[34m当前时间:${Since_Today},三个月之前:${Until_Today}\033[0m"

#创建一个临时目录
mkdir -p /tmp/statistics_git
for Project in ${Mos_Project[*]}
  do
    cd /tmp/statistics_git
    git clone ssh://xiaojin@192.168.1.29:29418/${Project} -b ${branch} &>/dev/null
    echo -e "\033[35m${Project} ${branch}:\033[0m"
    cd ${Project}
    for user in ${Users[*]}
       do
        git log --since==${Since_Today} --until=${Until_Today} --author="${user}" --pretty=tformat: --numstat | gawk -vuser="$user" '{ add += $1 ; subs += $2 ; loc += $1 - $2 ;if(NF==3)num+=1} END { printf "提交者: "user" 增加行数: %s 删除行数 : %s 总共行数: %s 修改文件数: %s \n",add,subs,loc,num }'
    done
done

rm -fr /tmp/statistics_git

方法二:用python工具(gitstats)统计

[root@platform_4 scripts]# cat android_statistics_gitsubmit.sh 
#!/bin/bash

read -p "输入统计Android分支的代码线:" branch

git_judge(){
    if [ $? -eq 0 ];then
         echo "正在拉去分支${branch}...."
    else
         echo "${branch}分支不存在"
         exit
    fi
}

main(){
    mkdir -p /tmp/statistics_android
    cd /tmp/statistics_android
    echo '正在拉取代码......'
    git clone ssh://xiaojin@192.168.1.29:29418/app/android/portal -b ${branch} &>/dev/null
    git_judge
    #统计生成tar包
    cd /tmp/statistics_android/portal
    echo '正在统计代码.....'
    /usr/local/src/gitstats/gitstats . android_${branch} &>/dev/null
    mkdir -p /opt/git_software/android
    tar zcf /opt/git_software/android/android_${branch}_`date +%F`_git.tar.gz android_${branch}
    rm -fr /tmp/statistics_android
    echo "文件生成路径:/opt/git_software/android/android_${branch}_`date +%F`_git.tar.gz"
}

main

  

posted @ 2018-10-17 14:14  阿进,fighting  阅读(...)  评论(... 编辑 收藏