git & gerrit & shell

g公司使用Gerrit改善评审流程. 比较麻烦.gerrit提交后会触发vertifyCI, 实施代码扫描.

这一堆过程, 打印出一堆信息, 都在log中, 所以处理log就需要自己写shell了.

复制代码
ssh -p 29418 xxxxx@xxxxxx gerrit query --format=JSON --patch-sets --all-approvals --commit-message --comments change:3920147

#提取log中的http:// url, 取第一条
ssh -p 29418 xxxxx@xxxxxx gerrit query --format=JSON --comments change:3920147|head -n 1 | jq '.comments'|jq '.[] | .message'|grep -oh "https.*/" | head -n 1


#log

java -jar ~/bin/jenkins-cli.jar -s https://xxxxxxx/xxxxx/ -auth xxxxx:xxxxxx console jobName 472

复制代码

 

其中用到几个工具, jq, 是一个解析json的工具, 功能非常强大:

jq

https://stedolan.github.io/jq/manual/#Basicfilters

https://www.cnblogs.com/bhlsheji/p/5345192.html

https://www.cnblogs.com/lurenjiashuo/p/bash-json-jq.html

 

gerrit query

https://gerrit-documentation.storage.googleapis.com/Documentation/2.13.7/cmd-query.html

https://gerrit-documentation.storage.googleapis.com/Documentation/2.13.7/json.html

 

另外关于正则表达式的贪婪非贪婪模式:

https://www.cnblogs.com/xudong-bupt/p/3586889.html

 

https://gerrit-documentation.storage.googleapis.com/Documentation/2.13.7/user-search.html

 

grep

grep 仅显示匹配部分,(默认是显示匹配到的行)

grep -oh "abc" xxx.log

abc可以为正则表达式

 

posted @   multitude  阅读(289)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示