Gerrit历史记录查询

本文介绍如何查询Gerrit指定状态的patch set,并分段保存为Json文件,便于后续用Python等工具处理成Excel。首先查看最近500条记录,然后继续查询500-1000条,详细查询命令可参考官方文档。
Python3.11

Python3.11

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

查询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




您可能感兴趣的与本文相关的镜像

Python3.11

Python3.11

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值