使用 GitHub V3 API (REST) 创建分叉 [英] Creating a fork with the GitHub V3 API (REST)

查看:19
本文介绍了使用 GitHub V3 API (REST) 创建分叉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 REST 使用 GitHub V3 API 分叉一个存储库,但是,我在根据文档发出 POST 请求时遇到问题(https://developer.github.com/v3/repos/forks/#create-a-fork).

I'm trying to fork a repo using the GitHub V3 API via REST, however, I am having issues making a POST request as per the docs (https://developer.github.com/v3/repos/forks/#create-a-fork).

基本上,到目前为止我所拥有的:

Basically, what I have so far:

  • 具有 OAuth 令牌的登录用户
  • 对 API 的 POST 请求设置(URL:https://api.github.com/repos/carmichaelalonso/infiniteflight/forks/) - 我正在使用 hurl.it 对此进行测试以开始
  • 请求中的标头:一个名称为 Authorization,值为 'token ...',另一个指定 Content-Type,值为 application/json
  • 具有以下 JSON 的主体:{"organization" : "shortlisthome"}(shortlisthome 是我尝试将存储库分叉到的帐户.
  • A logged-in user with an OAuth Token
  • A POST request setup to the API (URL: https://api.github.com/repos/carmichaelalonso/infiniteflight/forks/) - I am testing this with hurl.it to begin with.
  • Headers in the request: one has the name Authorization with the value 'token ...', the other specifies Content-Type with the value application/json
  • A body with the following JSON: {"organization" : "shortlisthome"} (shortlisthome is the account I am trying to fork the repo to.

我不打算将它分叉给一个组织,而不是一个标准的用户帐户,这是我感到困惑的地方.当我运行请求时,我没有收到任何身份验证错误或 404 错误(我以前有过,但我错误地输入了不正确的值,导致了此类错误).

I am not intending to fork this to an organization, instead of a standard user account, which is where I am getting confused. When I run the request, I do not get any authentication errors or 404 errors (I previously had but I had been entering incorrect values by mistake, causing such errors).

当我运行这个请求时,我得到以下结果(一个 422 无法处理的请求):

When I run this request though, I get the following result (a 422 unprocessable request):

{
    "message": "Validation Failed",
    "documentation_url": "---url-to-docs---",
    "errors": [
        {
            "resource": "Fork",
            "code": "invalid",
            "field": "organization"
        }
    ]
}

我不确定我是否能够将其分叉给标准用户,或者我的请求是否存在错误.请让我知道我是否可以提供更多信息(第一次在这里发帖,所以对惯例有点不熟悉).谢谢!

I am unsure whether or not I am able to fork this to a standard user, or if it is an error with my request. Please let me know if I can provide any more info (first post here so a bit unfamiliar with the convention). Thanks!

推荐答案

为了让 shortlisthome fork 仓库您需要像他们一样进行身份验证.您尝试分叉的存储库是公开的,因此您需要做的就是为shortlisthome 然后提出与您现在提出的请求类似的请求.唯一的区别是您不需要提供 {"organization": "shortlisthome"} 的 JSON 正文.

In order for shortlisthome to fork the repository you need to authenticate as them. The repository you're trying to fork is public, so all you need to do is obtain a OAuth token for shortlisthome and then make a similar request to the one you're making now. The only difference will be that you do not need to provide the JSON body of {"organization": "shortlisthome"}.

就其价值而言,可选的 JSON 正文旨在供您在您是具有适当权限的组织成员并且想要将存储库分叉到该组织时使用.除非您通过身份验证,否则您无法将仓库分叉到其他人的帐户.

For what it is worth, the optional JSON body is intended for you to use when you are a member of an organization with proper permissions and you want to fork the repository to that organization. You cannot fork a repository to someone else's account unless you are authenticated as them.

这篇关于使用 GitHub V3 API (REST) 创建分叉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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