如何在拉取请求上创建问题评论?

How to create an issue comment on a pull request?

根据 的说法,PR 只是一个问题,上面有一些事情。

如何获取关联的问题id?

我刚刚看到 issue_url 作为拉取请求对象的属性。 此外,PR 有方法 create_review_comment 但没有方法 create_issue_comment

这样的方法会是什么样子?

如何在合并请求中创建问题评论?

我能够通过从 PR 编号中获取问题来做到这一点。实际上,在 github 中,每次创建拉取请求时都会创建一个 "hidden" 问题。

所以下面的代码有效:

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)

也可以使用 other ways to get the issue from PR number.

不确定是否有比这更直接的方法

这适用于我当前的 pygithub:

from github import Github

g = Github(GITHUB_TOKEN)
repo_name = 'Org/repo'
repo = g.get_repo(repo_name)
pr = repo.get_pull(PR_NUMBER)
pr.create_issue_comment('test')