如何利用JQ过滤量超过0的条目?
我有一个gitHub命令行调用的结果,其中包括以下JSON格式:
[
{
"name": "repository-1",
"pullRequests": {
"totalCount": 129
}
},
{
"name": "repository-2",
"pullRequests": {
"totalCount": 1143
}
},
{
"name": "repository-3",
"pullRequests": {
"totalCount": 78
}
},
{
"name": "repository-4",
"pullRequests": {
"totalCount": 0
}
}
]
这是gh repo列表的输出org-repo -json pullrequests,name
我还有更多的存储库,我的目标是是获取所有具有0个拉请求的存储库的列表,以便我可以对这些请求(存档)行事。
如何使用JQ
进行此操作?
我已经尝试过:
.[].pullRequests.totalCount -> This gives me the numeric value of each record
.[].pullRequests.totalCount,.[].name -> This gives me the list from above and then the list of repository names
如何过滤存储库列表以仅显示存储库名称pullrequests.totalcount = 0
I have the results of a Github Commandline call with the following JSON format:
[
{
"name": "repository-1",
"pullRequests": {
"totalCount": 129
}
},
{
"name": "repository-2",
"pullRequests": {
"totalCount": 1143
}
},
{
"name": "repository-3",
"pullRequests": {
"totalCount": 78
}
},
{
"name": "repository-4",
"pullRequests": {
"totalCount": 0
}
}
]
This is the output of gh repo list ORG-REPO --json pullRequests,name
I have many many more repositories in there and my goal is to get a list of all repositories that have 0 pull requests so that I can act on those (archive).
How can I do this utilizing jq
?
I've tried:
.[].pullRequests.totalCount -> This gives me the numeric value of each record
.[].pullRequests.totalCount,.[].name -> This gives me the list from above and then the list of repository names
How can I filter the list of repositories to only show the repository name where pullRequests.totalCount = 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
选择
以按照标准过滤,此处.pullrequests.totalcount == 0
和map
将输入阵列:如果您只对名称,将其添加到映射中:
demo
如果您想要名称为newline-列表 -分开的原始文本而不是json字符串数组,在元素上迭代并使用
-raw-of-oftput
或-r
用于输出:demo
Use
select
to filter by criteria, here.pullRequests.totalCount == 0
, andmap
that onto the input array:Demo
If you are only interested in the names, add that to the mapping:
Demo
If you want the names as a list of newline-separated raw texts rather than a JSON array of strings, iterate over the elements and use the
--raw-output
or-r
for the output:Demo