【问题标题】:How can I use the GitHub Rest API to update a repository that is part of an organization?如何使用 GitHub Rest API 更新属于组织的存储库?
【发布时间】:2021-02-01 18:10:42
【问题描述】:

我有大量的 GitHub 存储库,这些存储库被分类到各个组织中。我希望使用以下 API 调用将存储库的可见性批量更改为公开:

curl -u {user}:{pat} -H "Accept: application/vnd.github.v3+json"  -X PATCH https://api.github.com/repos/{user}/angular.powershifter -d '{"private":false}'

据我所知,最好的是 API 调用 (see github docs)。上面示例中的{user]{pat} 是实际值,{pat} 选择了所有选项。 {user} 既是 repo 的所有者,也是组织的所有者。

我得到的回应是404,其正文如下。

{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/reference/repos#update-a-repository"
}
  1. 是否可以使用 API 设置组织下的仓库属性?
  2. 什么是 API 调用?
  3. 如果你能指出我的文档,奖励积分!

谢谢。

【问题讨论】:

  • 尝试添加-H "Content-Type: application/json"
  • 没有帮助

标签: github-api


【解决方案1】:

使用基于承载令牌的身份验证。 Github 正在弃用基于密码的身份验证。

curl \
 -H 'Authorization: Bearer ${GITHUB-TOKEN}' \
 -X PATCH \
 -H "Accept: application/vnd.github.v3+json" \
 https://api.github.com/repos/${OWNER}/${repo} \
 -d '{"private":"false"}' 

github 文档的链接 https://docs.github.com/en/free-pro-team@latest/rest/overview/other-authentication-methods

【讨论】:

    【解决方案2】:
    1. 是的,这是可能的。

    2. 我也遇到了一些问题。
      简短回答使用不记名令牌(正如@shek 所说),并将 false 更改为“false”:

      curl -v -H "授权:承载 ${GITHUB_TOKEN}"
      -X补丁https://api.github.com/repos/${ORGANIZATION}/${REPO} -H "接受:application/vnd.github.v3+json" -d '{"private": "false"}';

    请注意,您的令牌在创建令牌时可以完全控制私有存储库: full control of private repositories image

    该链接非常混乱,因为例如,如果您需要从 GitHub 获取所有存储库,则必须使用:

    https://api.github.com/orgs/${ORGANIZATION}/repos?${parameters}
    

    此外,当您需要更改权限时,您需要使用:

    https://api.github.com/orgs/${ORGANIZATION}/teams/${TEAM}/repos/${ORGANIZATION}/${REPO}
    

    (请注意 PATCH 命令中缺少的 orgs)。

    1. GitHub 存储库文档:
      https://docs.github.com/en/rest/reference/repos#update-a-repository
      GitHub 身份验证方法(来自 @shek):
      https://docs.github.com/en/free-pro-team@latest/rest/overview/other-authentication-methods

    【讨论】:

      猜你喜欢
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 2016-02-12
      • 2020-10-24
      • 2023-04-07
      • 2021-04-26
      • 1970-01-01
      相关资源
      最近更新 更多