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

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

问题描述

我试图通过REST使用GitHub V3 API分发repo,但是,根据文档发出POST请求时出现问题( https://developer.github.com/v3/repos/forks/#create-a-fork )。



基本上,我到目前为止:

- 具有OAuth令牌的已登录用户

- POST请求设置API(网址 - https://api.github.com/repos/carmichaelalonso/infiniteflight/ forks / ) - 我正在用hurl.it来测试它,以开始。

- 请求中的标题:其名称为'Authorization',值为'token ...'另一个用值'application / json'指定'Content-Type'

- 一个具有以下JSON的主体:'{organization:shortlisthome}'(shortlisthome是我尝试的帐户分叉回购。



我不是打算把它分给一个组织,而不是一个标准的用户帐户,这是我感到困惑的地方。当我运行请求时,我没有得到任何认证错误或404错误(我以前有过,但是我错误地输入了错误的值,导致了这样的错误)。



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

  {
message :验证失败,
documentation_url:--- url-to-docs ---,
errors:[
{
resource :Fork,
code:invalid,
field:organization
}
]
}

我不确定我是否可以将此分叉到标准用户,或者是否与我的请求有关。请让我知道,如果我可以提供更多的信息(首先发布在这里,因此有点不熟悉公约)。
Thanks!

解决方案

为了让 shortlisthome 来分叉您需要认证的存储库。您正在尝试分发的存储库是公开的,因此您只需获取OAuth令牌即可然后向你现在正在做的那个提出类似的请求。唯一的区别是您不需要提供 {organization:shortlisthome} 的JSON正文。

值得一提的是,当您是具有适当权限的组织的成员并且要将存储库分发给该组织时,可选的JSON正文供您使用。除非您通过身份验证,否则您无法将存储库分发给其他人的帐户。


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:
- 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.

I am not intending to fork this to an organisation, instead to 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).

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!

解决方案

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"}.

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天全站免登陆