我一直在寻找一种将我的私有(private)存储库转换为公共(public)存储库的方法,但由于它们太多了,我更喜欢使用简单的方法并求助于 GitHub API,但是到目前为止,这个正如我所发现的,只允许编辑公开存储库的可见性。查看最新的文档,我意识到在经过身份验证时唯一可用于访问的端点是( Repositories , Endpoints available ):
GET/user/repos
POST/user/repos
POST/user/projects
我还尝试使用浏览器控制台并在请求更改可见性时生成日志,但它似乎没有向 GitHub API 发出任何请求。
最佳答案
您可以使用此 REST endpoint 将存储库的可见性设置为公开(或私有(private)) :
PATCH /repos/{owner}/{repo}
这确实适用于私有(private)的存储库(尽管 your comment )。如果 repo 已经具有所请求的可见性,API 将返回一条错误消息来指示该状态。
可见性
参数
Can be
public
orprivate
. If your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+,visibility
can also beinternal
. Thevisibility
parameter overrides theprivate
parameter when you use both along with thenebula-preview
preview header.
例子
curl
curl \
-X PATCH \
-H "Accept: application/vnd.github.nebula-preview+json" \
https://api.github.com/repos/octocat/hello-world \
-d '{"visibility":"public"}'
gh
gh api -X PATCH /repos/octocat/hello-world -fvisibility=public --preview nebula
关于github - 是否可以使用 GitHub API 更改私有(private)仓库的可见性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64732670/