使用github cli循环浏览PR列表?

发布于 2025-01-22 10:48:17 字数 271 浏览 4 评论 0原文

我正在寻找有关如何使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无远思近则忧 2025-01-29 10:48:17

您可以在一个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按摩JSON逗号分隔列表(请参阅 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"

: - ([[:digit:]]+),然后使用它将所有pr放在找到spark的情况下,但未置于数字;然后,它用正则表达式第一匹配的捕获组取代了身体,仅返回数字。

最后,它重新排列为阵列并转换为CSV。

You could do everything in one gh invocation:

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'

The --json parameter selects URL and the description, and --jq massages the JSON into a comma-separated list (see 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"

The jq command first defines a regular expression SPARK-([[:digit:]]+), then uses it to drop all PRs where SPARK 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文