44
55; ; Author: István Karaszi <ikaraszi@gmail.com>
66; ; Version: 0.1.0
7- ; ; Package-Requires: ((emacs "28.1") (magit "4.5.0"))
7+ ; ; Package-Requires: ((emacs "28.1") (magit "4.5.0") (transient "0.8.0") )
88; ; Keywords: tools, vc
99; ; URL: https://github.com/function-artisans/magit-standup
1010
4040; ;; Code:
4141
4242(require 'magit )
43+ (require 'transient )
4344
4445(defgroup magit-standup nil
4546 " Collect recent git commits for standup notes."
@@ -212,12 +213,15 @@ LINK-PREFIX is the org link prefix string, or nil for plain text."
212213 " \n " ))))
213214 repo-commits))
214215
215- (defun magit-standup--gather ()
216+ (defun magit-standup--gather (&optional since-date repos )
216217 " Gather recent commits across all configured repositories.
218+ SINCE-DATE, when non-nil, overrides the computed since date.
219+ REPOS, when non-nil, overrides `magit-standup-repos' .
217220Returns an alist of (REPO-PATH . BRANCH-COMMITS) suitable for
218221`magit-standup--format-org' ."
219- (let* ((since-date (magit-standup--since-date))
220- (repos (or (magit-standup--resolve-repos magit-standup-repos)
222+ (let* ((since-date (or since-date (magit-standup--since-date)))
223+ (repos (or repos
224+ (magit-standup--resolve-repos magit-standup-repos)
221225 (list (magit-toplevel)))))
222226 (mapcar (lambda (repo )
223227 (cons repo
@@ -230,15 +234,10 @@ Returns an alist of (REPO-PATH . BRANCH-COMMITS) suitable for
230234 (when-let ((win (get-buffer-window magit-standup--buffer-name)))
231235 (quit-window t win)))
232236
233- ;;;### autoload
234- (defun magit-standup ()
235- " Display recent git commits as `org-mode' standup notes.
236- Collects commits from all repos in `magit-standup-repos' (or the
237- current repo if that is nil) and displays them in a
238- `*magit-standup*' buffer."
239- (interactive )
240- (let* ((repo-commits (magit-standup--gather))
241- (link-package (or magit-standup-link-package
237+ (defun magit-standup--display (repo-commits )
238+ " Display REPO-COMMITS in the `*magit-standup*' buffer.
239+ REPO-COMMITS is an alist as returned by `magit-standup--gather' ."
240+ (let* ((link-package (or magit-standup-link-package
242241 (magit-standup--detect-link-package)))
243242 (buf (get-buffer-create magit-standup--buffer-name))
244243 (link-prefix (magit-standup--link-prefix link-package)))
@@ -253,6 +252,56 @@ current repo if that is nil) and displays them in a
253252 (evil-local-set-key 'normal " q" #'magit-standup-quit )))
254253 (pop-to-buffer buf)))
255254
255+ (defun magit-standup--default-repos ()
256+ " Return resolved repo paths as a list of normalized directory names."
257+ (mapcar (lambda (d ) (directory-file-name (expand-file-name d)))
258+ (or (magit-standup--resolve-repos magit-standup-repos)
259+ (when-let ((top (magit-toplevel)))
260+ (list top)))))
261+
262+ (defun magit-standup--read-repos (prompt _initial-input _history )
263+ " Read repo directories with `completing-read-multiple' .
264+ PROMPT is shown to the user. Returns a comma-separated string."
265+ (string-join (completing-read-multiple prompt (magit-standup--default-repos)) " ," ))
266+
267+ (transient-define-infix magit-standup--since ()
268+ :description " Since date"
269+ :class 'transient-option
270+ :shortarg " -d"
271+ :argument " --since="
272+ :reader #'transient-read-date
273+ :init-value (lambda (obj )
274+ (unless (oref obj value)
275+ (oset obj value (magit-standup--since-date)))))
276+
277+ (transient-define-infix magit-standup--repos ()
278+ :description " Repositories"
279+ :class 'transient-option
280+ :shortarg " -r"
281+ :argument " --repos="
282+ :reader #'magit-standup--read-repos )
283+
284+ (transient-define-suffix magit-standup--run ()
285+ " Run the standup with the selected options."
286+ :key " s"
287+ :description " Show standup"
288+ (interactive )
289+ (let* ((args (transient-args 'magit-standup ))
290+ (since (transient-arg-value " --since=" args))
291+ (repos-str (transient-arg-value " --repos=" args))
292+ (repos (when repos-str (split-string repos-str " ," ))))
293+ (magit-standup--display
294+ (magit-standup--gather since repos))))
295+
296+ ;;;### autoload (autoload 'magit-standup "magit-standup" nil t)
297+ (transient-define-prefix magit-standup ()
298+ " Show a menu for generating standup notes."
299+ [" Options"
300+ (magit-standup--since)
301+ (magit-standup--repos)]
302+ [" Actions"
303+ (" s" " Show standup" magit-standup--run)])
304+
256305(provide 'magit-standup )
257306
258307; ;; magit-standup.el ends here
0 commit comments