From 6b6b9d4ea21eaab9bf252ceafd2df836e3f5a2b2 Mon Sep 17 00:00:00 2001 From: Julien Masson Date: Tue, 17 Mar 2020 11:00:33 +0100 Subject: [PATCH] ghub-fetch-repository: Fetch reviewThreads, baseRefOid/headRefOid 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 --- ghub-graphql.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/ghub-graphql.el b/ghub-graphql.el index 880eb06..80593d8 100644 --- a/ghub-graphql.el +++ b/ghub-graphql.el @@ -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)] @@ -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 @@ -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