gpt4 book ai didi

github - 使用 GitHub 的 API 创建拉取请求

转载 作者:行者123 更新时间:2023-12-05 05:10:55 24 4
gpt4 key购买 nike

我正在尝试使用此文档直接使用它的 REST API 向 GitHub 发出拉取请求:

https://developer.github.com/v3/pulls/#create-a-pull-request

我已经创建了一个公共(public)存储库,并尝试通过 API 检索拉取请求的操作,并且工作正常。但是当我尝试使用此操作创建拉取请求时:

POST /repos/:owner/:repo/pulls

还有这个 body :

    {
"title": "Amazing new feature",
"body": "Please pull this in!",
"head": "theOwner:new-branch",
"base": "master"
}

然后我从响应中收到此消息:

{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/pulls/#create-a-pull-request"
}

我提出请求的完整网址是:

https://api.github.com/repos/alvarocallero/node-test/pulls

我正在使用的请求正文是否正确?可能是“head”的值不正确。

最佳答案

我在同一个存储库中创建了一个 feature 分支,我想针对它创建一个 Pull 请求。之后,我调用了问题中提到的 api POST/repos/:owner/:repo/pulls,正文如下:

{
"title": "Amazing new feature",
"body": "Please pull this in!",
"head": "feature",
"base": "master"
}

正如您所看到的,因为我的 feature 分支与我正在创建 Pull 请求的 master 在同一个 repo 中,所以我刚刚在 head 中提到了它的名称。

在此之后,我还确保我通过了 Authorization(Basic Auth),并且当我调用 API 时,在 github 中创建了 Pull 请求。

然后我尝试在不传递授权 header 的情况下调用上述 API,我得到了 404。因此,我认为您需要更正正文中的 head 值,正如您在评论中提到的那样,您的分支与您正在创建 Pull 请求的 master 位于同一 repo 中。并确保传递 Authorization header

关于github - 使用 GitHub 的 API 创建拉取请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56027634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com