All comments for a commit - Answered

schema-request
community-help

#1

Is there a way to get all comments for a particular commit using the GraphQL API?

In the documentation, CommitCommentThread seems to be what I need, however I cant seem to get at it in the API.

[Feature Request] I’d like to query comments that apply to a particular hunk and/or line.

This query allows me to get all comments from a particular repository. I need more granularity.

query repositoryComments {
  rateLimit {
    remaining
    nodeCount
  }
  repository(owner: "stinb", name: "gitahead") {
    commitComments(last: 1) {
      totalCount
      edges {
        node {
          commit {
            oid
            id
            messageHeadline
            messageBody
          }
          body
        }
      }
    }
  }
}

In a perfect world, I’d do something like this:

query lineComment {
  repository(owner: "stinb", name: "gitahead") {
    commitComments(oid: "git-hash", line: 4, positon: 5) {
      edges {
        node {
          body
        }
      }
    }
  }
}

Where line could be a range of lines I want comments for. Position would represent specific comment in the list.


#2

Thank you for the schema request @shanegramlich. I’ve opened an issue internally and will update here when I know more.

Cheers,

Lizz


#3

@LizzHale Just curious, how often are these internal issues reviewed? What are my chances of getting a response in the near future? I’m considering implementing the “rest api v3” version of this feature. However, I can switch around priorities if a solution were to be available in the next couple weeks.

@community

  • Is there a way to get all comments for a particular commit using the GraphQL API?
  • How do I implement CommitCommentThread?

#4

Hey @shanegramlich. Great question! We’re always working to improve GitHub and review these requests regularly.

We can’t say if/when we may add a feature, however your feedback has definitely been recorded.

Lizz


#5

Is CommitCommentThread implemented? If so, can someone post a simple example of how to access it?


#6

Hi @shanegramlich

Is there a way to get all comments for a particular commit using the GraphQL API?

I’ve been looking into this for you and this is possible through the comments connection on the Commit object. Here’s an example:

query {
  repository(owner: "example", name: "example") {
    object(oid: "3176a2b94c2245bd9556d2b108444f4346988f08") {
      ... on Commit {
        comments(first: 50) {
          nodes {
            body
          }
        }
      }
    }
  }
}

You mentioned in the original post that you’d like to be able filter that with a range of lines. This isn’t currently possible but I’ll make sure to specify that in the feature request issue that I opened internally.

Is CommitCommentThread implemented? If so, can someone post a simple example of how to access it?

Yes. The CommitCommentThread is one of the types that can be returned from the PullRequestTimeline

A simple example might look like:

query {
  repository(owner: "example", name: "example") {
    pullRequests(first: 5) {
      nodes {
        timeline(first: 5) {
          nodes {
            ...on CommitCommentThread {
              commit {
                oid
              }
              comments(first: 5) {
                nodes {
                  body
                }
              }
            }
          }
        }
      }
    }
  }
}

#7

Wow, that one line opened me up to the world of GraphQL Fragments

Thank you so much for spending time on this!


#8

It’s my pleasure @shanegramlich! I’m so glad it was helpful!


#9

For the sake of completeness and the future benefit of anyone reading this thread:

This is a query of all comments for a commit. Comments can then be ordered by path, position, and timestamp (published at).

query {
  repository(owner: "stinb", name: "gitahead-test") {
    object(oid: "a0bad38889e50aaad137aa0814bc5d66e29aed58") {
      ... on Commit {
        comments(first: 50) {
          nodes {
            path
            position
            publishedAt
            body
            author {
              login
            }
          }
        }
      }
    }
  }
}

oid: the git hash of a specific commit
path: the filename associated with this comment. An empty path indicates a general comment on the entire commit.
position: the diff line number this comment was made on
publishedAt: the timestamp on this comment
body: the textual content of this comment
login: the GitHub login of the author of this comment