1

我正在尝试通过使用 PyGithub/PullRequest.py 中定义的 create_review() 函数将它们发布到拉取请求中来自动化向学生报告自动化测试结果的工作流程。这是我的简单代码片段:

#!/usr/bin/env python
import os
import sys
from github import Github

if __name__ == "__main__":
   url = sys.argv[1]

# create the gh access
gh = Github("7c841411d84ce30f6c09a15ce283aa11f73f8da2");

repo = gh.get_organization('ADEN-GHCL-PILOT').get_repos(url)[0]
print(repo)

pr = repo.get_pulls(state='open')[0]
print(pr)

tresults = "this is a test of a multi-line comment|this should be the second line".split('|')
print(tresults)
pr.create_review(comments=tresults)

这将产生以下输出:

% ./add_pull_request_comment.py https://github.com/ADEN-GHCL-PILOT/hw1-test-swm-tc1.git
Repository(full_name="ADEN-GHCL-PILOT/hw1-test-swm-tc1")
PullRequest(title="Feedback", number=1)
['this is a test of a multi-line comment', 'this should be the second line']
Traceback (most recent call last):
  File "./add_pull_request_comment.py", line 20, in <module>
    pr.create_review(comments=tresults)
  File "/Users/Scott/anaconda3/lib/python3.7/site-packages/github/PullRequest.py", line 493, in create_review
    "POST", self.url + "/reviews", input=post_parameters
  File "/Users/Scott/anaconda3/lib/python3.7/site-packages/github/Requester.py", line 319, in requestJsonAndCheck
    verb, url, parameters, headers, input, self.__customConnection(url)
  File "/Users/Scott/anaconda3/lib/python3.7/site-packages/github/Requester.py", line 342, in __check
    raise self.__createException(status, responseHeaders, output)
github.GithubException.GithubException: 422 {"message": "Invalid request.\n\nFor 'items', \"this is a test of a multi-line comment\" is not an object.\nFor 'items', \"this should be the second line\" is not an object.", "documentation_url": "https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review"}

输出显示存储库和拉取请求都存在 - 并且评论输入预计是一个列表,它是......

我很难过......并且会感激地接受任何指导。

更新@下午 4 点 34 分:

我发现 create_review 期望评论是评论对象列表,而不是字符串列表。这些包括文件的路径、文件中的行位置,然后是正文。我知道使用 create_review_comment() 创建评论对象,但是由于路径无效而失败...

4

0 回答 0