Add LLM-based PR review
Added `gptel-pr-review` to `init-ai.el` for reviewing pull requests with specific prompts using gptel. Introduced `forge-pullreq-diff` in `init-git.el` to retrieve PR diffs as strings. These changes integrate AI capabilities for improved PR feedback and comment functionality.
This commit is contained in:
parent
e2538b3666
commit
6898a3e8e5
@ -273,6 +273,20 @@ Assistant: Write a short story about a dragon who discovers a hidden talent that
|
||||
:stream t
|
||||
:system "You are a professional software engineer.")))
|
||||
|
||||
(defun gptel-pr-review (pr)
|
||||
"Review a pull request via gptel."
|
||||
(interactive (list (forge-get-pullreq
|
||||
(forge-read-pullreq "Review PR: "))))
|
||||
(let ((diff (forge-pullreq-diff pr))
|
||||
(name (generate-new-buffer-name (format "*PR review: %s*" (oref pr title))))
|
||||
(prompt "Review the changes in this pull request. Highlight any issues, suggest improvements, and provide explanations for your suggestions. Keep your feedback specific and concise."))
|
||||
(gptel name nil diff t)
|
||||
(with-current-buffer name
|
||||
(goto-char (point-max))
|
||||
(newline)
|
||||
(insert (gptel-prompt-prefix-string))
|
||||
(insert (format " %s" prompt)))))
|
||||
|
||||
(with-eval-after-load 'git-commit
|
||||
(keymap-set git-commit-mode-map "C-c RET" #'gptel-commit-message))
|
||||
|
||||
|
@ -66,7 +66,21 @@
|
||||
(advice-add 'forge-topic-at-point :around
|
||||
(lambda (oldfn &rest args)
|
||||
(ignore-errors (apply oldfn args))))
|
||||
(defun forge-pullreq-diff (pullreq)
|
||||
"Return the diff of the pull request visited or at point as a string."
|
||||
(when pullreq
|
||||
(let* ((base-ref (oref pullreq base-ref))
|
||||
(head-ref (oref pullreq head-ref))
|
||||
(base-remote (forge--get-remote base-ref))
|
||||
(head-remote (forge--get-remote head-ref))
|
||||
(default-directory (magit-toplevel))
|
||||
(range (format "%s/%s..%s/%s" base-remote base-ref head-remote head-ref)))
|
||||
(with-temp-buffer
|
||||
(magit-git-insert "diff" range)
|
||||
(buffer-string)))))
|
||||
(defun forge-diff-for-pr ()
|
||||
"Display a diff buffer for the pull request currently being created.
|
||||
Does not work on already-created pull requests."
|
||||
(interactive)
|
||||
(let ((target forge--buffer-base-branch)
|
||||
(source forge--buffer-head-branch))
|
||||
|
Loading…
Reference in New Issue
Block a user