Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 4

Graphql PullRequest Timeline review threads

Solved! Go to Solution.

I would like to use the timeline api in graphql to retrieve reviews and their comments however this isn't possible currently in the graphql api. 

 

what I'm trying to do is: 

 

{
  repositoryOwner(login: "k0shk0sh") {
    repository(name: "FastHub") {
      pullRequest(number: 2442) {
        timelineItems(first: 20, itemTypes: [PULL_REQUEST_REVIEW, PULL_REQUEST_REVIEW_THREAD]) {
          nodes {
            __typename
            ... on PullRequestReview {
              authorAssociation
              author {
                login
                avatarUrl
                url
              }
              body
              createdAt
              state
              resourcePath
              comments(first: 5) {
                totalCount
                nodes {
                  pullRequestReview {
                    body
                  }
                  author {
                    login
                    avatarUrl
                    url
                  }
                  diffHunk
                  body
                  originalPosition
                  path
                  outdated
                }
              }
            }
            ... on PullRequestReviewThread {
              isResolved
              viewerCanResolve
              viewerCanUnresolve
              comments(first: 5) {
                nodes {
                  body
                  author {
                    login
                    url
                    avatarUrl
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 

The `PullRequestReview -> Comments` always return single comment however if you look at the PR (https://github.com/k0shk0sh/FastHub/pull/2442) it actually has two and the count always return 1 rather than 2 and `PullRequestReviewThread` basically never return anything! 

 

I would like to retrieve the review with its comment in one query and I reckon that this should work out of the box! but it doesn't! any help will be appreciated! 

 

related issue: https://github.community/t5/GitHub-API-Development-and/GraphQL-API-returning-only-the-first-comment-...

3 Replies
Community Manager
Message 2 of 4

Re: Graphql PullRequest Timeline review threads

I've updated you query somewhat to give you the information you're asking for. Currently, pull request review threads don't appear in the `timelineItems` connection, but you can get them by querying them separately:

 

{
  repositoryOwner(login: "k0shk0sh") {
    repository(name: "FastHub") {
      pullRequest(number: 2442) {
        reviewThreads(first: 100) {
          nodes {
            comments(first: 100) {
              nodes {
                author {
                  login
                }
                body
              }
            }
          }
        }
        timeline(first: 100) {
          nodes {
            __typename
          }
        }
        timelineItems(first: 20, itemTypes: [ISSUE_COMMENT, PULL_REQUEST_REVIEW, PULL_REQUEST_REVIEW_THREAD, PULL_REQUEST_COMMIT_COMMENT_THREAD]) {
          nodes {
            __typename
            ... on PullRequestReview {
              authorAssociation
              author {
                login
                avatarUrl
                url
              }
              body
              createdAt
              state
              resourcePath
              comments(first: 5) {
                totalCount
                nodes {
                  pullRequestReview {
                    body
                  }
                  author {
                    login
                    avatarUrl
                    url
                  }
                  diffHunk
                  body
                  originalPosition
                  path
                  outdated
                }
              }
            }
            ... on PullRequestReviewThread {
              isResolved
              viewerCanResolve
              viewerCanUnresolve
              comments(first: 5) {
                nodes {
                  body
                  author {
                    login
                    url
                    avatarUrl
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Also, there is only one pull request review comment in the pull request you link to. The other comments are a pull request review thread, consisting of two comments as of this writing. The various types of pull request comments is complex and daunting, but there are ways to get all the informaiton out of the API.

 

I hope that helps!

Copilot Lvl 3
Message 3 of 4

Re: Graphql PullRequest Timeline review threads

I got over this now and ignored the other comments in the timeline and went with minimal display of the review with just the reviewer comment and decided upon user clicking on the review they should go to a screen where they can be able to see the full list using 

 

reviewThreads(ID_OF_REVIEW: "some id"){
          nodes {
            comments(first:100){
              totalCount
              nodes {
                body
              }
            }
          }
        }

but this isn't possible right now and i'm kinda blocked. 

 

is there any way that I can retrieve  reviewThreads by review_ID? I'm trying to stay away from json API and me trying the graphql every single day kinda gets me frustrated as everything I want is either not possible or is there but doesn't work as expected! I would really love if there is something already implemented and i'm missing it! 

 

Solution
Copilot Lvl 3
Message 4 of 4

Re: Graphql PullRequest Timeline review threads

well I figured it out myself while working on commits I found out that I could use the `node` and pass an id and since PullRequestView is extending node then its pretty straight and easy. 

this is what I used:

 

 

{
  node(id: "MyPullRequestReviewId") {
    ... on PullRequestReview {
      body
      comments (first:100){
        nodes {
          body
        }
      }
    }
  }
}

and what's even awesome: is that it returns every single comment ;)