Eya*_*ber 2 git bash github github-api
I was wondering how to check if a pull request has conflicts on GitHub using a script from my PC? There is a nice solution mentioned here to do it via GitHub actions: /sf/answers/5018458931/
However, taking the same script from https://olivernybroe/action-conflict-finder and running it on my PC won't work unless I do a local merge. After identifying the conflicts I would have to discard the local merge. This process seems inefficient and I was looking for a "cleaner" and faster solution.
以下是如何在没有 shell 循环的情况下通过管道传输它,并使用gh api -q内置jq查询或jq本身解析 JSON。
#!/usr/bin/env sh
REPOSITORY_NAME=
OWNER=
gh api -H "Accept: application/vnd.github+json" \
"repos/${OWNER}/${REPOSITORY_NAME}/pulls" --cache 1h |
jq -j --arg curbranch "$(git rev-parse --abbrev-ref HEAD)" \
'
.[] | select(
(.base.ref == $curbranch) and
(.state == "open") and
(.draft == false)
) | .number | tostring + "\u0000"
' |
xargs -0 -I{} \
gh api -H "Accept: application/vnd.github+json" \
"repos/${OWNER}/${REPOSITORY_NAME}/pulls/{}" --cache 1h \
-q '
"PR #" + (.number | tostring) + ": " +
.title + " is " +
if .mergeable != false then "mergeable" else "not mergeable" end
'
Run Code Online (Sandbox Code Playgroud)
或者使用while read -r循环而不是循环,xargs这在某些 Windows 环境中似乎有问题:
gh api -H "Accept: application/vnd.github+json" \
"repos/${OWNER}/${REPOSITORY_NAME}/pulls" --cache 1h |
jq -r --arg curbranch "$(git rev-parse --abbrev-ref HEAD)" \
'
.[] | select(
(.base.ref == $curbranch) and
(.state == "open") and
(.draft != true)
) | .number
' | while read -r pr; do
gh api -H "Accept: application/vnd.github+json" \
"repos/${OWNER}/${REPOSITORY_NAME}/pulls/${pr}" --cache 1h \
-q '
"PR #" + (.number | tostring) + ": " +
.title + " is " +
if .mergeable != false then "mergeable" else "not mergeable" end
'
done
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1582 次 |
| 最近记录: |