使用curl重命名Github上的标签

时间:2018-12-13 10:28:29

标签: rest github label github-api

我正在尝试使用REST API重命名Github上的标签。我可以阅读标签

curl https://api.github.com/repos/adamschmideg/label-cleanup/labels/question

,它返回一个不错的json。

但是,当我尝试按照Updating a Github issue label上的文档进行更新并执行

时,
curl \
    --request PATCH \
    https://api.github.com/repos/adamschmideg/label-cleanup/labels/question \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{\"name\": \"just-a-question\"}"

它返回一条消息“未找到”。对于不存在的标签,它将返回相同的消息。

我怎么了?

1 个答案:

答案 0 :(得分:1)

这似乎是public repository,这意味着任何人都可以看到其标签。

但是,更新标签受到限制。您需要authenticate,例如通过在您的基本身份验证请求中添加-u "username"

curl \
    -u "adamschmideg" \  # <-- Right here
    --request PATCH \
    https://api.github.com/repos/adamschmideg/label-cleanup/labels/question \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{\"name\": \"just-a-question\"}"

如果您使用的是双重身份验证,并且想要使用此处所示的基本身份验证,则需要include a one-time code in a special X-GitHub-OTP header as well

GitHub还支持以标头或URL参数形式发送的OAuth2令牌,该令牌不需要任何特殊步骤,如果您使用的是2FA,则建议使用。

The reason是“找不到”而不是“请验证”之类的

  

在某些地方,需要身份验证的请求将返回404 Not Found,而不是403 Forbidden。这是为了防止私有存储库意外泄露给未经授权的用户。