Skip to content

Commit c726d61

Browse files
committed
Change magit-standup to use transient inputs
1 parent abc4d3a commit c726d61

3 files changed

Lines changed: 102 additions & 14 deletions

File tree

Easkfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
(depends-on "emacs" "28.1")
1414
(depends-on "magit" "4.5.0")
15+
(depends-on "transient" "0.8.0")
1516

1617
(development
1718
(depends-on "package-lint")

magit-standup.el

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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

@@ -40,6 +40,7 @@
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'.
217220
Returns 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

test/magit-standup-test.el

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,44 @@
244244
(let ((magit-standup-repos nil))
245245
(spy-on 'magit-toplevel :and-return-value "/home/user/my-project")
246246
(let ((result (magit-standup--gather)))
247-
(expect (mapcar #'car result) :to-equal '("/home/user/my-project"))))))
247+
(expect (mapcar #'car result) :to-equal '("/home/user/my-project")))))
248+
249+
(it "uses provided since-date instead of computing one"
250+
(let ((magit-standup-repos '("/tmp/a")))
251+
(magit-standup--gather "2026-02-01")
252+
(expect 'magit-standup--since-date :not :to-have-been-called)
253+
(expect 'magit-standup--collect-commits
254+
:to-have-been-called-with "/tmp/a" "2026-02-01")))
255+
256+
(it "uses provided repos instead of configured ones"
257+
(let ((magit-standup-repos '("/tmp/should-not-use")))
258+
(let ((result (magit-standup--gather nil '("/tmp/x" "/tmp/y"))))
259+
(expect 'magit-standup--resolve-repos :not :to-have-been-called)
260+
(expect (mapcar #'car result) :to-equal '("/tmp/x" "/tmp/y")))))
261+
262+
(it "uses both overrides together"
263+
(let ((magit-standup-repos '("/tmp/ignored")))
264+
(magit-standup--gather "2026-03-01" '("/tmp/override"))
265+
(expect 'magit-standup--since-date :not :to-have-been-called)
266+
(expect 'magit-standup--resolve-repos :not :to-have-been-called)
267+
(expect 'magit-standup--collect-commits
268+
:to-have-been-called-with "/tmp/override" "2026-03-01"))))
269+
270+
(describe "magit-standup--display"
271+
(after-each
272+
(when-let ((buf (get-buffer magit-standup--buffer-name)))
273+
(kill-buffer buf)))
274+
275+
(it "creates a buffer with org-mode content"
276+
(let ((magit-standup-link-package 'none))
277+
(magit-standup--display
278+
'(("/home/user/my-repo" . (("main" . ("abc\0Fix bug"))))))
279+
(let ((buf (get-buffer magit-standup--buffer-name)))
280+
(expect buf :not :to-be nil)
281+
(with-current-buffer buf
282+
(expect major-mode :to-be 'org-mode)
283+
(expect buffer-read-only :to-be t)
284+
(expect (buffer-string) :to-match "my-repo")
285+
(expect (buffer-string) :to-match "abc Fix bug"))))))
248286

249287
;;; magit-standup-test.el ends here

0 commit comments

Comments
 (0)