diff --git a/emacs/.emacs.d/config/init-ai.el b/emacs/.emacs.d/config/init-ai.el index 73617ec..9fd39b5 100644 --- a/emacs/.emacs.d/config/init-ai.el +++ b/emacs/.emacs.d/config/init-ai.el @@ -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)) diff --git a/emacs/.emacs.d/config/init-git.el b/emacs/.emacs.d/config/init-git.el index 4e162f3..f022169 100644 --- a/emacs/.emacs.d/config/init-git.el +++ b/emacs/.emacs.d/config/init-git.el @@ -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))