Skip to content

Commit

Permalink
ghub-fetch-repository: Fetch reviewThreads, baseRefOid/headRefOid
Browse files Browse the repository at this point in the history
PullRequestReviewThread object is a threaded list of review comments
for a given pull request.

headRefOid and baseRefOid are the rescpective head and base SHA
reference for a given pull request.

The GitHub GraphQL API has limitations, Individual calls cannot
request more than 500,000 total nodes.
Thus in order to fetch reviewThreads from a pull-request, we need to
fetch these data in a dedicated function: `ghub-fetch-review-threads`

Otherwise we will have this kind of error message:
"By the time this query traverses to the comments connection, it is
requesting up to 1,000,000 possible nodes which exceeds the maximum
limit of 500,000."

Source:
https://docs.github.com/en/free-pro-team@latest/graphql/overview/resource-limitations
https://docs.github.com/en/free-pro-team@latest/graphql/reference/objects#pullrequestreviewthread

Signed-off-by: Julien Masson <[email protected]>
  • Loading branch information
JulienMasson committed Feb 5, 2021
1 parent 87770d3 commit 6a93d7a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions ghub-graphql.el
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ behave as for `ghub-request' (which see)."
body
(baseRef name
(repository nameWithOwner))
baseRefOid
(headRef name
(repository (owner login)
nameWithOwner))
headRefOid
(assignees [(:edges t)]
id)
(reviewRequests [(:edges t)]
Expand All @@ -170,6 +172,34 @@ behave as for `ghub-request' (which see)."
(labels [(:edges t)]
id)))))

(defconst ghub-fetch-repository-review-threads
'(query
(repository
[(owner $owner String!)
(name $name String!)]
(pullRequests [(:edges t)
(:singular pullRequest number)
(orderBy ((field UPDATED_AT) (direction DESC)))]
number
baseRefOid
headRefOid
(reviewThreads [(:edges t)]
id
line
originalLine
diffSide
(resolvedBy login)
(comments [(:edges t)]
id
databaseId
(author login)
createdAt
updatedAt
body
(replyTo databaseId)
(originalCommit oid)
path))))))

(cl-defun ghub-fetch-repository (owner name callback
&optional until
&key username auth host forge
Expand Down Expand Up @@ -231,6 +261,27 @@ data as the only argument."
:headers headers
:errorback errorback))

(cl-defun ghub-fetch-review-threads (owner name number callback
&optional until
&key username auth host forge
headers errorback)
"Asynchronously fetch forge data about the review threads from a pull-request.
Once all data has been collected, CALLBACK is called with the
data as the only argument."
(ghub--graphql-vacuum (ghub--graphql-prepare-query
ghub-fetch-repository-review-threads
`(repository pullRequests (pullRequest . ,number)))
`((owner . ,owner)
(name . ,name))
callback until
:narrow '(repository pullRequest)
:username username
:auth auth
:host host
:forge forge
:headers headers
:errorback errorback))

;;; Internal

(cl-defstruct (ghub--graphql-req
Expand Down

0 comments on commit 6a93d7a

Please sign in to comment.