![](/img/trans.png)
[英]Is it possible to get a list of all open PRs in a git repo without using the HTTPS API or the `gh` CLI tool?
[英]Looping through list of PRs using GitHub CLI?
我正在寻找有关如何使用 GitHub CLI 解决特定脚本问题的建议。 假设我使用gh search prs "SPARK-" --match body
命令来获取所有 prs 的列表,其中正文包含 SPARK- 短语。 现在,我想遍历该 pr 列表,output 和该 pr 的 url 以及它的 SPARK 编号(在 pr 正文的某处,有文字说“SPARK-”,后跟一个唯一的 5 位数字)。 关于如何处理这个问题的任何想法? 我很难弄清楚如何使用我的 gh cli output(或者如果可能的话?),让我们在一些 bash 脚本中说,并弄清楚如何专门隔离 SPARK 号。
您可以在一次gh
调用中完成所有操作:
gh search prs "SPARK-" --match body --json url,body --jq '
"SPARK-([[:digit:]]+)" as $re
| map(select(.body | test($re)))
| .[].body |= match($re).captures[0].string
| map([.url, .body])[]
| @csv'
--json
参数选择 URL 和描述,--jq 将--jq
按摩到一个逗号分隔的列表中(参见jq playground ):
"https://github.com/just4jc/CSE6242-Data-and-Visual-Analytics/pull/32","1298180"
"https://github.com/h950059h/kafka-examples/pull/33","1298180"
"https://github.com/terrorizer1980/zeppelin/pull/75","2420837"
"https://github.com/muyenzo/reference-architectures/pull/10","574943"
"https://github.com/microsoft/az-python/pull/461","35714"
"https://github.com/radanalyticsio/streaming-amqp/pull/38","1298181"
"https://github.com/orysmudi/tensorflow/pull/78","573164"
"https://github.com/apache/iceberg/pull/4479","30669"
"https://github.com/alonsoir/strata-2016/pull/17","1298180"
jq 命令首先定义了一个正则表达式SPARK-([[:digit:]]+)
,然后用它来删除所有发现SPARK
但后面没有数字的 PR; 然后它用正则表达式的第一个匹配项的捕获组替换正文,只返回数字。
最后重排为arrays,转换为CSV。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.