如何使用命令行在组织内邀请用户加入私有github存储库 [英] How to invite a user to a private github repo within an organisation using the command line

查看:56
本文介绍了如何使用命令行在组织内邀请用户加入私有github存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将用户添加到组织内的私有Github存储库 中.从此帖子开始,我只是更改了API端点以应对组织(如

I am trying to add users to a private Github repo within an organisation. Starting from this post, I've simply changed the API endpoint to cope with organizations (as explained here), and I end up with the following command:

gh api orgs/MY_ORG/repos/MY_USER_NAME/MY_REPO/collaborators/COLLABORATOR_USER_NAME -f '{"permission":"maintain"}';

此命令系统地返回404错误(请注意,当我仅尝试检查用户是否可以访问存储库(即上述命令的 GET 版本)时,也会收到404错误).我还需要提及的是,这似乎不是一个琐碎的 gh auth login 问题,因为 gh repo create MY_ORG/MY_REPO 这样的命令可以正常工作.

This command systematically returns a 404 error (note that I also get a 404 when I just try to check if a user has access to a repo, i.e. the GET version of the above command). I also need to mention that this doesn't seem to be a trivial gh auth login issue since a command like gh repo create MY_ORG/MY_REPO works fine.

这里还有一些技术细节:

Here is also some technical details:

  • os:macosx 10.15.16
  • git:2.24.3
  • gh:1.1.0

推荐答案

由于进行了一些调查,我主动在这里回答我自己的问题(感谢mislav的

I take the initiative to answer my own question here since after some investigations (thanks to mislav for his help) and trials and errors, I ve found the proper way to add collaborators to a GitHub repo within an organization with the CLI. I think it is worth posting it, hopefully this will help others.

邀请外部协作者加入组织内的存储库

gh api -X PUT repos/:org/:repo/collaborators/:username -f permission=:perm

-X PUT 指定请求为 PUT ,而不是 GET (默认请求).回购的标识符由:org/:repo 指定(请注意,如果回购不在组织内,则标识符将为:owner/:repo ).:perm 参数指示访问的类型,默认值为 push (请参见

the -X PUT specifies that the request is a PUT and not a GET (default request). The repo's identifier is specified by :org/:repo (note that if the repo is not under an organization, the identifier will be :owner/:repo). The :perm argument indicates the type of access, the default value is push (see here)

因此,假设我想为组织 got 下的仓库 winterfell 提供 admin 访问 jonsnow 的权限,我将使用以下命令

So assume I want to provide admin access to jonsnow to the repo winterfell under the organization got, I will use the following command

gh api -X PUT repos/got/winterfell/collaborators/jonsnow -f permission=admin

请注意,如果您直接发送回购邀请,则用户将以外部协作者(而非组织成员)的身份出现

Note that if you send an invite for the repo directly, the user will appear as an outside collaborator (not as an organization member)

将成员添加到组织中,并邀请他参加回购

您只需要事先将用户加入组织即可

You just need to include the user as a member to the organisation beforehand with

gh api -X PUT /orgs/:org/memberships/:username -f role=:role

,然后您可以使用与上述相同的命令(即

and then you can provide him access to a specific repo with the same command as above, i.e.

gh api -X PUT repos/:org/:repo/collaborators/:username -f permission=:perm

请注意,各种:role 的值可以在

Note that the value for the various :role can be found here

这篇关于如何使用命令行在组织内邀请用户加入私有github存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆