当我尝试通过Github的v3 API创建评论评论时出了什么问题?

时间:2017-06-27 23:21:19

标签: github github-api

我试图通过Github的v3 API创建审核提交,但我没有成功。考虑this repository。只有一个pull request,出于这个问题的目的,让我们说我想留下所要求的更改'审查该公关。这是我的代码:

#!/usr/bin/env python3

import requests
import json

TOKEN='YOUR_TOKEN_HERE'

REPO = "blt/experiment-repo"
PR_NUM = 1
COMMIT_SHA_1 = "4160bee478c3c985eaaa35f161cc922fe20b354a"
COMMIT_SHA_2 = "df9d13a2e35f9b6c228e1f30ea30585ed85af26a"

def main():
    pr_comment_headers = {
        'user-agent': 'benedikt/0.0.1',
        'Authorization': 'token %s' % TOKEN,
        # Accept header per
        # https://developer.github.com/changes/2016-12-16-review-requests-api/
        'Accept': 'application/vnd.github.black-cat-preview+json',
    }

    msg = "BLEEP BLOOP I AM A ROBOT"
    payload = { 'commit_id': COMMIT_SHA_2,
                'body': msg,
                'event': "REQUEST_CHANGES" }

    # Per https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
    review_url = "https://api.github.com/repos/%s/pulls/%s/reviews" % (REPO, PR_NUM)
    res = requests.post(review_url, headers = pr_comment_headers,
            json = json.dumps(payload))
    print(res)
    print(res.text)


if __name__ == '__main__':
    main()

我已经在代码评论中标记了我发现要点击的API端点以及有效负载。除了,我必须在某个地方搞砸,因为当我运行上述程序时,我会收到:

<Response [422]>
{"message":"Validation Failed","errors":["Variable commitOID of type GitObjectID was provided invalid value","Variable event of type PullRequestReviewEvent was provided invalid value"],"documentation_url":"https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review"}

我已经验证了提交SHA是Github显示的确切的,而REQUEST_CHANGES是文档中的字符串。

我错过了什么?

1 个答案:

答案 0 :(得分:1)

我认为您需要让请求对请求正文进行编码,而不是使用@ApplicationScoped public class MyShiroSessionManager{ @EJB private MyFacade myEjb; public void onRememberedSubject(@Observes Session session){ myEjb.updateUserInformation(session); } } 自行编码,如下所示:json.dumps()