branch: externals/ellama
commit a7abe668f5cff0914baf573fc188521db8e65ace
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>
Add commit message generation
Add a new customizable variable
`ellama-generate-commit-message-template` and a function
`ellama-generate-commit-message` to generate commit messages based on
diffs using ellama.
---
ellama.el | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/ellama.el b/ellama.el
index 609d6ce46e..ebae39c0d6 100644
--- a/ellama.el
+++ b/ellama.el
@@ -5,7 +5,7 @@
;; Author: Sergey Kostyaev <[email protected]>
;; URL: http://github.com/s-kostyaev/ellama
;; Keywords: help local tools
-;; Package-Requires: ((emacs "28.1") (llm "0.6.0") (spinner "1.7.4"))
+;; Package-Requires: ((emacs "28.1") (llm "0.6.0") (spinner "1.7.4") (compat
"29.1"))
;; Version: 0.11.6
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Created: 8th Oct 2023
@@ -42,6 +42,8 @@
(require 'info)
(require 'shr)
(require 'eww)
+(require 'vc)
+(require 'compat)
(eval-when-compile (require 'rx))
(defgroup ellama nil
@@ -266,6 +268,17 @@ PROMPT is a prompt string."
:group 'ellama
:type 'string)
+(defcustom ellama-generate-commit-message-template "You are professional
software developer.
+Write concise commit message based on diff. First line should
+contain short title described major change in functionality. Then
+one empty line. Then detailed description of all changes. Reply
+with commit message only. Diff:
+
+%s"
+ "Prompt template for `ellama-generate-commit-message'."
+ :group 'ellama
+ :type 'string)
+
(defcustom ellama-make-format-prompt-template "Render the following text as a
%s:\n%s"
"Prompt template for `ellama-make-format'."
:group 'ellama
@@ -1626,6 +1639,26 @@ the full response text when the request completes (with
BUFFER current)."
(text (buffer-substring-no-properties beg end)))
(ellama-stream text)))
+;;;###autoload
+(defun ellama-generate-commit-message ()
+ "Generate commit message based on diff."
+ (interactive)
+ (let* ((default-directory
+ (if (string= ".git"
+ (car (reverse
+ (cl-remove
+ ""
+ (file-name-split default-directory)
+ :test #'string=))))
+ (file-name-parent-directory default-directory)
+ default-directory))
+ (diff (with-temp-buffer
+ (vc-diff-internal
+ nil (vc-deduce-fileset t) nil nil nil (current-buffer))
+ (buffer-substring-no-properties (point-min) (point-max)))))
+ (ellama-stream
+ (format ellama-generate-commit-message-template diff))))
+
;;;###autoload
(defun ellama-ask-line ()
"Send current line to ellama chat."