使用Github CLI向组织仓库添加外部合作者。

3

我正在使用 gh-cli

我想要在组织(my-org)的私有仓库(my-repo-in-org)中添加外部协作者。

我可以使用这个 gh 命令来显示协作者。

gh api repos/my-org/myrepo-in-org/collaborators

根据文档 添加存储库合作者,我尝试使用以下方法添加拥有推送权限的协作者(collaborator_name):

gh api repos/my-org/my-repo-in-org/collaborators/collaborator-name -f '{"permission"="push"}'

但是获得:

{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest"
}
gh: Not Found (HTTP 404)

有什么线索可以帮我做到这一点吗?
我需要管理多个仓库和多个用户,并希望自动化处理。

1个回答

3
使用-f/--raw-field指定参数时,默认的HTTP方法是POST,但此调用需要PUT方法。您可以使用-X--method参数告诉gh指定方法:
gh api repos/{owner}/{repo}/collaborators/{username} -X PUT -f permission='push'

来自文档

默认情况下,HTTP请求方法通常为“GET”,如果添加了任何参数,则为“POST”。使用“--method”覆盖该方法。

选项列表中:

-X, --method string           The HTTP method for the request (default "GET")

谢谢@Bertrand Martel,它起作用了。-X Put是我错过的东西。 - wolszakp
我必须使用-F permission=read,因为-f permission=read会被忽略。 - Luca Gibelli

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接