如何使用go-github获取Pull Request的Conversation评论而非评审评论?
解决方案
要获取Pull Request Conversation区域的普通评论(非代码评审关联的评论),你需要调用Issues.ListComments方法,而非PullRequests.ListComments——后者确实专门返回与代码行绑定的评审评论。
示例代码
import "github.com/google/go-github/v56/github" // 获取PR Conversation区域的评论 comments, _, err := client.Issues.ListComments(ctx, ghOrgName, ghRepoName, *value.PullRequest.Number, &github.IssueListCommentsOptions{}) if err != nil { // 处理错误逻辑 }
核心区别说明
PullRequests.ListComments:返回代码评审类评论,这类评论关联PR中的具体代码行,属于评审流程的一部分。Issues.ListComments:由于GitHub的Pull Request本质是特殊的Issue,该方法会返回PR页面Conversation区域的所有普通讨论评论(包括PR描述下的回复、非代码关联的对话等)。
内容的提问来源于stack exchange,提问作者Michal Škultý
相关产品推荐
相关产品推荐

