使用github cli循环浏览PR列表?
我正在寻找有关如何使用GitHub CLI解决某个脚本问题的建议。假设我使用了gh搜索prs“ spark-” - 匹配主体
命令以获取所有PRS的列表,其中包含火花短语的正文。现在,我想循环浏览该PR的列表,并输出该PR的URL以及它的火花号码(PR的某个地方,有文字在“ Spark-”上说“ Spark-”,其次是独特的5位数字)。关于如何解决这个问题的想法?我很难使用我的GH CLI输出来弄清楚我如何能够构建此循环(或者是否可能吗?),在某些bash脚本中说,并弄清楚如何具体隔离火花数字。
I'm looking for advice on how to approach a certain scripting problem using GitHub CLI. Let's say I used the gh search prs "SPARK-" --match body
command to get a list of all prs with the body containing the SPARK- phrase. Now, I want to loop through that list of prs, and output the url of that pr along with it's SPARK number (somewhere in the body of the pr, there is text saying "SPARK-" followed by a unique 5 digit number). Any ideas on how to approach this? I'm having difficulty figuring how I might be able to construct this loop using my gh cli output (or if it's even possible?), let's say in some bash script, and figuring out how to specifically isolate the SPARK number.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在一个
gh
调用中完成所有操作:- JSON
参数选择URL和描述,以及-JQ
按摩JSON逗号分隔列表(请参阅 jq playground ): - ([[:digit:]]+),然后使用它将所有pr放在找到
spark
的情况下,但未置于数字;然后,它用正则表达式第一匹配的捕获组取代了身体,仅返回数字。最后,它重新排列为阵列并转换为CSV。
You could do everything in one
gh
invocation:The
--json
parameter selects URL and the description, and--jq
massages the JSON into a comma-separated list (see jq playground):The jq command first defines a regular expression
SPARK-([[:digit:]]+)
, then uses it to drop all PRs whereSPARK
is found, but not followed by digits; then it replaces the body with the capture group of the first match of the regex, returning just the number.Finally, it rearranges into arrays and converts to CSV.