Невозможно создать многострочные комментарии с помощью PyGithub / PullRequest.create_review () - PullRequest
1 голос
/ 08 июля 2020

Я пытаюсь автоматизировать рабочий процесс для представления результатов автоматизированных тестов студентам, отправляя их в запрос на перенос с помощью функции create_review (), определенной в PyGithub / PullRequest.py. Вот мой простой фрагмент кода:

#!/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"}

Вывод показывает, что и репозиторий, и запрос на вытягивание существуют, а ввод комментариев - Ожидается, что это будет список, а это ...

Я в тупике ... и с благодарностью приму любое руководство.

Обновление в 16:34:

Я выяснили, что create_review ожидал, что комментарий будет списком объектов комментария, а не списком строк. К ним относятся путь к файлу, позиция строки в файле, а затем основной текст. Я знаю, что создаю объект комментария с помощью create_review_comment (), но это не удается из-за неверного пути ...

...