List pull request comments using go-github

110 Views Asked by At

I am trying to retrieve list of comments for particular Pull Request using go-github. I am interested in comments listed in the section Conversation not the review comments.

I tried to use PullRequests.ListComments, but it returns review comments

PullRequests.ListComments(ctx, ghOrgName, ghRepoName, *value.PullRequest.Number, &github.PullRequestListCommentsOptions{})

I didnt find suitable function in the documentation

Thanks in advance

1

There are 1 best solutions below

0
On

Might be a little late to answer this, you will need to use the issues endpoint https://docs.github.com/en/rest/guides/working-with-comments?apiVersion=2022-11-28#pull-request-comments

so, the code will look something like this

comments, _, err := client.Issues.ListComments(ctx, "ghOrgName", "ghRepoName", prNumber, &github.IssueListCommentsOptions{})
    if err != nil {
        return err
    }
    for _, comment := range comments {
        fmt.Println(*comment.Body)
    }