查询Gerrit指定状态的patch set,并保存到文件。采用分段查看首先查看最近500条的,再查看最近500-1000条的。以Json文件格式保存。后续处理做成Excel可以用Python等。
查询命令文档见https://review.openstack.org/Documentation/cmd-query.html
#!/bin/bash
#This is a script for get the history of the gerrit pathes
#USAGE: getpats project status time
#time meas after/since this time ,for exzampl 2017-01-01.every query will fetch 500 entries
if [ $# -lt 4 ];then
echo "wrong usage,USAGE: getpats.sh project status time,or see the script for more details "
exit 1
fi
segment=0
project=$1
status=$2
time=$3
savedfile=${project}${time}".re"
command=`ssh -p 29418 gerrit.louis.com gerrit query --format=JSON --start $segment status:$status after:$time projects:$project`
#每一次查询如果属于刚好满足查询条件的最后一次结果,返回结果最后一行有"moreChanges":false
judgecon=`ssh -p 29418 gerrit.louis.com gerrit query --format=JSON --start $segment status:$status after:$time projects:$project | grep '"moreChanges":false'`
if [ -n "$judgecon" ];then
#一次查询就返回所有的结果
echo "the results must less than 500,run the command once"
echo "$command" >> $savedfile
else
while [ -z "$judgecon" ]
do
echo "$command" >> $savedfile
((segment+=500))
command=`ssh -p 29418 gerrit.louis.com gerrit query --format=JSON --start $segment status:$status after:$time projects:$project`
judgecon=`ssh -p 29418 gerrit.louis.com gerrit query --format=JSON --start $segment status:$status after:$time projects:$project | grep '"moreChanges":false'`
done
echo "stopped at $segment,check if there any histories from this beginning"
lastcon=`ssh -p 29418 gerrit.louis.com gerrit query --format=JSON --start $segment status:$status after:$time projects:$project | grep "Change-Id"`
if [ -n "$lastcon" ];then
echo "There have missed moreChanges in the last query,now append them in the end"
echo "$command" >> $savedfile
fi
fi
本文介绍如何查询Gerrit指定状态的patch set,并分段保存为Json文件,便于后续用Python等工具处理成Excel。首先查看最近500条记录,然后继续查询500-1000条,详细查询命令可参考官方文档。
1万+

被折叠的 条评论
为什么被折叠?



