【问题标题】:Github API Auth not working with adding a comment on a pull requestGithub API Auth 无法在拉取请求上添加评论
【发布时间】:2016-01-27 14:47:55
【问题描述】:

根据另一个 stackoverflow 帖子,您应该使用问题 API 来向拉取请求添加评论。似乎合乎逻辑,因为我想发表顶级评论并且只想包含评论正文。

Create comment on pull request

我正在使用带有基本身份验证的以下请求,并尝试了我的密码和一次性令牌。我们使用 github 企业,所以主机是正确的。 cmets 的 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

【问题讨论】:

    标签: rest authentication curl github-api pull-request


    【解决方案1】:

    我们使用 github 企业,所以主机是正确的。

    没错,但是GitHub v3 page does mention:

    请注意,对于 GitHub Enterprise,与所有其他端点一样,您需要将 GitHub Enterprise 端点作为主机名以及您的用户名和密码传递:

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

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

    【讨论】:

      【解决方案2】:

      更直接的答案:

      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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-01-05
        • 1970-01-01
        • 2017-08-02
        • 2013-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多