Skip to content

Commit

Permalink
forge-{approve-pullreq,request-changes}: New commands
Browse files Browse the repository at this point in the history
Closes #377.
  • Loading branch information
tarsius committed Jan 13, 2025
1 parent 1f53f72 commit 90f46e4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
35 changes: 35 additions & 0 deletions lisp/forge-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,41 @@ point is currently on."
(insert (replace-regexp-in-string "^" "> " quote) "\n\n")))
(forge--display-post-buffer buf)))

(transient-define-suffix forge-approve-pullreq ()
"Approve the current pull-request."
:description "approve pull-request"
:inapt-if-not #'forge-current-pullreq
:transient nil
(interactive)
(let ((pullreq (forge-current-pullreq t)))
(unless (cl-typep (forge-get-repository pullreq) 'forge-github-repository)
(user-error "This command is only available for Github"))
(when-let ((buf (forge--prepare-post-buffer
(forge--format pullreq "%i;new-approval")
(forge--format pullreq "Approve pull-request #%i of %p"))))
(with-current-buffer buf
(setq forge--buffer-post-object pullreq)
(setq forge--submit-post-function #'forge--submit-approve-pullreq))
(forge--display-post-buffer buf))))

(transient-define-suffix forge-request-changes ()
"Request changes to the current pull-request."
:description "request changes"
:inapt-if-not #'forge-current-pullreq
:transient nil
(interactive)
(let ((pullreq (forge-current-pullreq t)))
(unless (cl-typep (forge-get-repository pullreq) 'forge-github-repository)
(user-error "This command is only available for Github"))
(when-let ((buf (forge--prepare-post-buffer
(forge--format pullreq "%i;new-request")
(forge--format
pullreq "Request changes for pull-request #%i of %p"))))
(with-current-buffer buf
(setq forge--buffer-post-object pullreq)
(setq forge--submit-post-function #'forge--submit-request-changes))
(forge--display-post-buffer buf))))

;;; Edit

(defun forge-edit-post ()
Expand Down
16 changes: 16 additions & 0 deletions lisp/forge-github.el
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,22 @@
:callback (forge--post-submit-callback)
:errorback (forge--post-submit-errorback)))

(cl-defmethod forge--submit-approve-pullreq ((_ forge-github-repository) repo)
(let ((body (magit--buffer-string nil nil t)))
(forge--ghub-post repo "/repos/:owner/:repo/pulls/:number/reviews"
`((event . "APPROVE")
,@(and (not (equal body "")) `((body . ,body))))
:callback (forge--post-submit-callback)
:errorback (forge--post-submit-errorback))))

(cl-defmethod forge--submit-request-changes ((_ forge-github-repository) repo)
(let ((body (magit--buffer-string nil nil t)))
(forge--ghub-post repo "/repos/:owner/:repo/pulls/:number/reviews"
`((event . "REQUEST_CHANGES")
,@(and (not (equal body "")) `((body . ,body))))
:callback (forge--post-submit-callback)
:errorback (forge--post-submit-errorback))))

(cl-defmethod forge--set-topic-title
((_repo forge-github-repository) topic title)
(forge--ghub-patch topic
Expand Down
4 changes: 3 additions & 1 deletion lisp/forge-topic.el
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,9 @@ This mode itself is never used directly."
["Actions"
("/f" forge-pull-this-topic)
("/b" forge-browse-this-topic)
("/c" forge-checkout-this-pullreq)]]
("/c" forge-checkout-this-pullreq)
("/A" forge-approve-pullreq)
("/R" forge-request-changes)]]
[forge--lists-group
["Set "
("-m" forge-topic-set-milestone)
Expand Down

0 comments on commit 90f46e4

Please sign in to comment.