# Type queries into this side of the screen, and you will 
# see intelligent typeaheads aware of the current GraphQL type schema, 
# live syntax, and validation errors highlighted within the text.

# We'll get you started with a simple query showing your username!
query($repo_owner:String!, $repo_name:String!, $pr_id:Int!) { 
  repository(owner: $repo_owner, name: $repo_name) {
    pullRequest(number: $pr_id) {
      id
      url
      state
      mergeable
      headRefName
      headRefOid
      baseRefName
      baseRefOid
      
      createdAt
      title
      body
      bodyHTML
      reactionGroups {
        content
        reactors { totalCount }
        viewerHasReacted
      }
      author {
        login
      }
      viewerCanUpdate

      viewerCanSubscribe
      viewerSubscription

      baseRef {
        refUpdateRule {
          requiredStatusCheckContexts
        }
      }

      labels(first: 100) {
        nodes {
          name
          color
        }
      }

      files(first: 100) {
        nodes {
          path
          additions
          deletions
        }
      }
      
      reviewRequests(first: 100) {
        nodes {
          requestedReviewer {
            __typename
            ... on User {
              login
            }
          }
        }
      }
      
      latestOpinionatedReviews(first: 100) {
        nodes {
          author {
            login
          }
          createdAt
          state
        }
      }
      
      reviewThreads(first: 100) {
        nodes {
          isCollapsed
          isResolved
          isOutdated
          path
          diffSide
          line
          startDiffSide
          startLine
          id
          comments(first: 100) {
            nodes {
              id
              databaseId
              viewerCanUpdate
              author {
                login
              }
              body
              bodyHTML
              createdAt
              reactionGroups {
                content
                reactors { totalCount }
                viewerHasReacted
              }
            }
          }
        }
      }
      
      assignees(first: 100) {
        nodes {
          login
        }
      }

      commits(first: 100) {
        nodes {
          commit {
            oid
            abbreviatedOid
            messageHeadline
          }
        }
      }

      latestCommits : commits(last: 1) {
        nodes {
          commit {
            oid
            statusCheckRollup {
              state
              contexts(first: 100) {
                nodes {
                  __typename
                  ... on CheckRun {
                    name
                    status
                    conclusion
                    title
                    annotations(first: 100) {
                      nodes {
                        annotationLevel
                        location {
                          start { line }
                          end { line }
                        }
                        message
                        path
                        title
                      }
                    }
                  }
                  ... on StatusContext {
                    context
                    description
                    state
                    targetUrl
                  }
                }
              }
            }
          }
        }
      }

      timelineItems(last: 100, itemTypes: [ISSUE_COMMENT, PULL_REQUEST_REVIEW, ASSIGNED_EVENT, MERGED_EVENT, CLOSED_EVENT, HEAD_REF_FORCE_PUSHED_EVENT, PULL_REQUEST_COMMIT, REVIEW_REQUESTED_EVENT, REVIEW_REQUEST_REMOVED_EVENT, UNASSIGNED_EVENT, REOPENED_EVENT, CROSS_REFERENCED_EVENT]) {
        totalCount
        filteredCount
        nodes {
          __typename
          ... on IssueComment {
            id
            databaseId
            viewerCanUpdate
            author {
              login
            }
            body
            bodyHTML
            createdAt
            reactionGroups {
              content
              reactors { totalCount }
              viewerHasReacted
            }
          }
          ... on PullRequestReview {
            id
            databaseId
            viewerCanUpdate
            body
            bodyHTML
            state
            author {
              login
            }
            createdAt
            reactionGroups {
              content
              reactors { totalCount }
              viewerHasReacted
            }
            
            comments(first: 100) {
              nodes {
                id
                databaseId
                diffHunk
                path
                author {
                  login
                }
                createdAt
              }
            }
          }
          ... on AssignedEvent {
            id
            createdAt
            actor {
              login
            }
            assignee {
              ... on User {
                login
              }
            }
          }
          ... on UnassignedEvent {
            id
            createdAt
            actor {
              login
            }
            assignee {
              ... on User {
                login
              }
            }
          }
          ... on MergedEvent {
            id
            createdAt
            actor {
              login
            }
            mergeRefName
          }
          ... on ClosedEvent {
            id
            createdAt
            actor {
              login
            }
          }
          ... on ReopenedEvent {
            id
            createdAt
            actor {
              login
            }
          }
          ... on HeadRefForcePushedEvent {
            id
            createdAt
            actor {
              login
            }
            beforeCommit {
              abbreviatedOid
            }
            afterCommit {
              abbreviatedOid
            }
          }
          ... on PullRequestCommit {
            id
            commit {
              abbreviatedOid
              messageHeadline
              pushedDate
            }
          }
          ... on ReviewRequestedEvent {
            id
            createdAt
            actor {
              login
            }
            requestedReviewer {
              ... on User {
                login
              }
            }
          }
          ... on ReviewRequestRemovedEvent {
            id
            createdAt
            actor {
              login
            }
            requestedReviewer {
              ... on User {
                login
              }
            }
          }
          ... on CrossReferencedEvent {
            id
            createdAt
            actor {
              login
            }
            source {
              ... on Issue {
                url
                title
              }
              ... on PullRequest {
                url
                title
              }
            }
          }
        }
      }

    }
  }
}