Skip to main content
 首页 » 编程设计

github之在拉取请求上创建评论

2024年09月07日16qq号

GitHub's comment API似乎允许您对拉取请求创建评论,但前提是您在差异中提供特定行号以进行评论。有没有办法在整个拉取请求上创建评论,相当于在 GitHub 的 Web 界面的拉取请求屏幕底部键入?

请您参考如下方法:

对的,这是可能的。 section of the API docs you are referencing与行注释有关(对 pull req 中提交的特定行的注释),并且文档说:

Pull Request Review Comments are comments on a portion of the unified diff. These are separate from Commit Comments (which are applied directly to a commit, outside of the Pull Request view), and Issue Comments (which do not reference a portion of the unified diff).


你需要的是那些问题评论,在 this page顶部有解释。 :

The Pull Request API allows you to list, view, edit, create, and even merge pull requests. Comments on pull requests can be managed via the Issue Comments API.


因此,为了创建拉取请求评论,您实际上需要创建一个问题评论(因为拉取请求会创建一个问题来管理它)。 page for Issue comments证实了这一点:

The Issue Comments API supports listing, viewing, editing, and creating comments on issues and pull requests.


所以, request you need to make是:
POST /repos/:owner/:repo/issues/:number/comments 
您如何知道要发布到哪个问题评论 URL?好吧,如果你看看 response for getting a single pull request ,您将看到它包含一个名为 _links 的属性。 ,并且这个属性有一个嵌套的 comments属性。这是您应该用于读取和创建拉取请求评论的 URL,与上面 POST 请求中使用的 URL 相同。