Skip to content

Commit 4571350

Browse files
committed
forge--submit-edit-post(github): Use graphql if possible
- For issues and pull-requests we could continue to use REST, but don't. - For pull-request replies we must continue to use REST because the GraphQL API does not support editing those. - For discussions we have to use GraphQL because the REST API does not editing supported.
1 parent df46d48 commit 4571350

1 file changed

Lines changed: 48 additions & 12 deletions

File tree

lisp/forge-github.el

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -823,18 +823,54 @@
823823
:errorback (forge--post-submit-errorback)))
824824

825825
(cl-defmethod forge--submit-edit-post ((_ forge-github-repository) post)
826-
(forge--ghub-patch post
827-
(cl-typecase post
828-
(forge-pullreq "/repos/:owner/:repo/pulls/:number")
829-
(forge-issue "/repos/:owner/:repo/issues/:number")
830-
(forge-post "/repos/:owner/:repo/issues/comments/:number"))
831-
(if (cl-typep post 'forge-topic)
832-
(pcase-let ((`(,title . ,body) (forge--post-buffer-text)))
833-
`((title . ,title)
834-
(body . ,body)))
835-
`((body . ,(magit--buffer-string nil nil t))))
836-
:callback (forge--post-submit-callback)
837-
:errorback (forge--post-submit-errorback)))
826+
(cl-typecase post
827+
((or forge-issue-post forge-pullreq-post)
828+
;; Cannot use GraphQL because we made the mistake to derive our ID
829+
;; from the number instead of their ID. `updatePullRequestComment'
830+
;; (or something equivalent under an inconsistent name) does not
831+
;; exist, so for that we would have to continue to use REST anyway.
832+
(forge--ghub-patch post
833+
"/repos/:owner/:repo/issues/comments/:number"
834+
`((body . ,(magit--buffer-string nil nil t)))
835+
:callback (forge--post-submit-callback)
836+
:errorback (forge--post-submit-errorback)))
837+
(t
838+
(forge--graphql
839+
`(mutation (,(cl-etypecase post
840+
(forge-discussion 'updateDiscussion)
841+
(forge-issue 'updateIssue)
842+
(forge-pullreq 'updatePullRequest)
843+
(forge-discussion-post 'updateDiscussionComment)
844+
(forge-discussion-reply 'updateDiscussionComment)
845+
(forge-issue-post 'updateIssueComment)
846+
(forge-pullreq-post 'updatePullRequestComment))
847+
[(input
848+
$input
849+
,(cl-etypecase post
850+
(forge-discussion 'UpdateDiscussionInput!)
851+
(forge-issue 'UpdateIssueInput!)
852+
(forge-pullreq 'UpdatePullRequestInput!)
853+
(forge-discussion-post 'UpdateDiscussionCommentInput!)
854+
(forge-discussion-reply 'UpdateDiscussionCommentInput!)
855+
(forge-issue-post 'UpdateIssueCommentInput!)
856+
(forge-pullreq-post 'UpdatePullRequestCommentInput!)))]
857+
clientMutationId))
858+
`((input (,(cl-etypecase post
859+
(forge-discussion 'discussionId)
860+
(forge-issue 'id)
861+
(forge-pullreq 'pullRequestId)
862+
(forge-discussion-post 'commentId)
863+
(forge-discussion-reply 'commentId)
864+
(forge-issue-post 'id)
865+
(forge-pullreq-post 'id))
866+
. ,(forge--their-id post))
867+
,@(if (cl-typep post 'forge-topic)
868+
(pcase-let ((`(,title . ,body) (forge--post-buffer-text)))
869+
`((title . ,title)
870+
(body . ,body)))
871+
`((body . ,(magit--buffer-string nil nil t))))))
872+
:callback (forge--post-submit-callback)
873+
:errorback (forge--post-submit-errorback)))))
838874

839875
(cl-defmethod forge--submit-approve-pullreq ((_ forge-github-repository) repo)
840876
(let ((body (magit--buffer-string nil nil t)))

0 commit comments

Comments
 (0)