简体   繁体   English

使用 GitHub CLI 遍历 PR 列表?

[英]Looping through list of PRs using GitHub CLI?

I'm looking for advice on how to approach a certain scripting problem using GitHub CLI.我正在寻找有关如何使用 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.假设我使用gh search prs "SPARK-" --match body命令来获取所有 prs 的列表,其中正文包含 SPARK- 短语。 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).现在,我想遍历该 pr 列表,output 和该 pr 的 url 以及它的 SPARK 编号(在 pr 正文的某处,有文字说“SPARK-”,后跟一个唯一的 5 位数字)。 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.我很难弄清楚如何使用我的 gh cli output(或者如果可能的话?),让我们在一些 bash 脚本中说,并弄清楚如何专门隔离 SPARK 号。

You could do everything in one gh invocation:您可以在一次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'

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

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; jq 命令首先定义了一个正则表达式SPARK-([[:digit:]]+) ,然后用它来删除所有发现SPARK但后面没有数字的 PR; 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.最后重排为arrays,转换为CSV。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM