Github API Auth 无法在拉取请求中添加评论

Github API Auth not working with adding a comment on a pull request

根据其他 Whosebug post,您应该使用问题 API 以便向拉取请求添加评论。似乎合乎逻辑,因为我想发表顶级评论并且只想包含评论正文。

Create comment on pull request

我正在使用以下带有基本身份验证的请求,并尝试了我的密码和一次性令牌。我们使用 github enterprise 所以主机是正确的。 Api评论区

https://developer.github.com/v3/issues/comments/#create-a-comment

我正在尝试的请求如下所示:

POST /repos/mobile/android/issues/1615/comments HTTP/1.1
Authorization: Basic XXXXXXXXXX
Content-Type: application/json
Cookie: logged_in=no
Host: ghe.megaleo.com
Connection: close
User-Agent: Paw/2.2.5 (Macintosh; OS X/10.10.5) GCDHTTPRequest
Content-Length: 33

{"body":"Here is a test comment"}

我收到 302 重定向响应

<html><body>You are being <a href="https://ghe.megaleo.com/login?return_to=https%3A%2F%2Fghe.megaleo.com%2Frepos%2Fmobile%2Fandroid%2Fissues%2F1615%2Fcomments">redirected</a>.</body></html>

还有其他方法可以进行身份​​验证吗?还是我做错了什么?等效的 curl 命令可能看起来像这样

curl -H "Content-type: application/json" -X POST -u username:password -d '{"body": "Here is a test comment on a pull request"}' https://ghe.megaleo.com/repos/mobile/android/issues/1615/comments

We use github enterprise so the host is correct.

没错,但是 GitHub v3 page does mention:

Note that for GitHub Enterprise, as with all other endpoints, you’ll need to pass in your GitHub Enterprise endpoint as the hostname, as well as your username and password:

$ curl https://hostname/api/v3/ -u username:password
                       ^^^^^^^

所以试试 https://ghe.megaleo.com/api/v3/repos/mobile/android/pulls/1615/comments

更直接的回答:

curl \
  -X POST \
  -H "Accept: application/vnd.github.v3+json" \
  http(s)://{hostname}/api/v3/repos/octocat/hello-world/pulls \
  -d '{"head":"head","base":"base"}'

详情请参考:https://docs.github.com/en/enterprise-server@3.1/rest/reference/pulls#create-a-pull-request