github - 是否可以使用 GitHub API 更改私有(private)仓库的可见性?

标签 github github-api

我一直在寻找一种将我的私有(private)存储库转换为公共(public)存储库的方法,但由于它们太多了,我更喜欢使用简单的方法并求助于 GitHub API,但是到目前为止,这个正如我所发现的,只允许编辑公开存储库的可见性。查看最新的文档,我意识到在经过身份验证时唯一可用于访问的端点是( RepositoriesEndpoints 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 or private. If your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+, visibility can also be internal. The visibility parameter overrides the private parameter when you use both along with the nebula-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/

相关文章:

git - 如何使用 Github Actions 查看最新提交?

Github 操作在作业之间共享工作空间/工件?

github - gitignore 没有忽略我添加的文件

javascript - GitHub API CORS 政策

objective-c - 如何让 Travis CI 构建和测试托管在 Github 上的 xcode 项目?

git - 更新远程服务器以从重命名的 Git 存储库中提取

github-api - github api 以及如何获取拉取的代码片段和注释

node.js - Nodejs Github api gist create - 接收Socket挂起

linux - 在 JSON 对象中扩展表达式的问题

github-api - Github webhooks - 预推钩子(Hook)