![](/img/trans.png)
[英]Bash script is returning "gh: Not Found (HTTP 404) Error: writing output failed: Invalid argument" when trying multiple actions on GitHub repos
[英]Why reading pull request data using github cli api causes "gh: Not Found (HTTP 404)" error when run from git-bash terminal?
當使用github cli api通過 git-bash 終端讀取拉取請求數據時,我收到“gh: Not Found (HTTP 404)”錯誤。 當我通過 PowerShell 終端或 wsl 運行完全相同的腳本時,效果很好。 知道為什么會這樣嗎?
我決定回答我自己的問題,因為我花了幾個小時才意識到這個問題的解決方案,而且我在網上的任何地方都找不到。 基本上,發生這種情況的原因純粹是由於路徑的編寫方式。 如果您從單詞“repos”之前刪除/
,那么該命令在 PowerShell、wsl 和 git-bash 終端上都運行良好。
所以正確的腳本應該是:
# GitHub CLI api
# https://cli.github.com/manual/gh_api
gh api \
-H "Accept: application/vnd.github+json" \
repos/OWNER/REPO/pulls/PULL_NUMBER
同樣,這與 GitHub API 文檔中正式編寫的內容不同,因為我刪除了“repos”一詞之前的/
。 我希望這對其他人也有幫助。
雖然REST API 中的 gh 代碼示例確實有一個額外的/
前綴,但實際的gh api 手冊頁沒有:
例子:
# list releases in the current repository
$ gh api repos/{owner}/{repo}/releases
# post an issue comment
$ gh api repos/{owner}/{repo}/issues/123/comments -f body='Hi from CLI'
端點參數中的占位符值“
{owner}
”、“{repo}
”和“{branch}
”將被當前目錄的存儲庫或GH_REPO
環境變量中指定的存儲庫中的值替換。請注意,在某些 shell(例如 PowerShell)中,您可能需要將任何包含“
{...}
”的值括在引號中,以防止 shell 將特殊含義應用於花括號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.