Skip to main content
 首页 » 编程设计

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

2025年05月04日14leader

根据 this question PR 只是一个问题,上面有一些事情。

如何获取关联的问题ID?

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

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

如何在 Pull Request 中创建问题评论?

请您参考如下方法:

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

所以下面的代码有效:

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 .

不知道有没有比这更直接的方法