pythongithub-apigithub3.py

How to create an issue comment on a pull request?


According to this question a PR is just an issue with some things on top.

How to get the associated issue id?

I just saw issue_url as attribute for the pull request object. Also, PR has the method create_review_comment but no method create_issue_comment.

How would such a method look like?

How to create an issue comment in the Pull Request?


Solution

  • I was able to do it by getting the issue from the PR number. Indeed, in github a "hidden" issue is created every time you create a pull request.

    So the following code worked:

    gh = ... # Connection
    repo = gh.repository(user, repo_name)
    pr = repo.create_pull(description, base, from_branch, detailed)
    issue = repo.issue(pr.number)
    issue.create_comment(comment)
    

    One could also use other ways to get the issue from PR number.

    Not sure if there is any way more straightforward than this