1

I am trying to automate a workflow for reporting automated test results to students by posting them in a pull request using the create_review() function defined in PyGithub/PullRequest.py. Here is my simple code snippet:

#!/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)

This results in the following output:

% ./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"}

The output shows that both the repository and the pull request exist - and the comments input is expected to be a list, which it is...

I am stumped... and will gratefully accept any guidance.

Update @ 4:34pm:

I figured out that the create_review was expecting the comment to be a list of Comment objects, not a list of strings. These include the path to a file, the line position within the file, and then the body text. I am know creating the comment object using create_review_comment(), but this fails due to the path being invalid...

0 Answers0