Skip to content

Commit

Permalink
forge-insert-{issues,pullreqs}: Add SPEC and HEADING arguments
Browse files Browse the repository at this point in the history
This allows wrapping these functions, while overriding certain aspects,
to define additional section inserters that apply additional filtering.

In `forge--insert-topics' use the heading as the "value", which is
necessary to tell different sections apart.

See #676.  Usage example:

  (defun forge-insert-assigned-issues ()
    "Insert a list of issues that are assigned to you.
  Mostly honor the buffer's filtering spec, overriding
  only the `assignee' slot."
    (when-let (((forge-db t))
               (repo (forge-get-repository :tracked?))
               (user (ghub--username repo))
               (spec (clone forge--buffer-topics-spec)))
      (oset spec assignee user)
      (forge-insert-issues spec "Assigned issues")))

  (magit-add-section-hook 'magit-status-sections-hook
                          #'forge-insert-assigned-issues
                          #'forge-insert-issues t)
  • Loading branch information
tarsius committed Jun 27, 2024
1 parent 1e144bd commit f09d222
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
14 changes: 8 additions & 6 deletions lisp/forge-issue.el
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,18 @@ can be selected from the start."
"<remap> <magit-visit-thing>" #'forge-visit-this-topic
"<remap> <forge--item-menu>" #'forge-topic-menu)

(defun forge-insert-issues ()
"Insert a list of issues."
(cl-defun forge-insert-issues (&optional (spec nil sspec) heading)
"Insert a list of issues, according to `forge--buffer-topics-spec'.
Optional SPEC can be used to override that filtering specification,
and optional HEADING to change the section heading."
(when-let (((forge-db t))
(repo (forge-get-repository :tracked?))
((oref repo issues-p))
(spec forge--buffer-topics-spec)
((memq (oref spec type) '(topic issue)))
(spec (clone spec)))
(spec (if sspec spec (clone forge--buffer-topics-spec)))
((memq (oref spec type) '(topic issue))))
(oset spec type 'issue)
(forge--insert-topics 'issues "Issues"
(forge--insert-topics 'issues
(or heading "Issues")
(forge--list-topics spec repo))))

;;; _
Expand Down
14 changes: 8 additions & 6 deletions lisp/forge-pullreq.el
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,17 @@ can be selected from the start."
"<remap> <magit-visit-thing>" #'forge-visit-this-topic
"<remap> <forge--item-menu>" #'forge-topic-menu)

(defun forge-insert-pullreqs ()
"Insert a list of pull-requests."
(cl-defun forge-insert-pullreqs (&optional (spec nil sspec) heading)
"Insert a list of pull-requests, according to `forge--buffer-topics-spec'.
Optional SPEC can be used to override that filtering specification,
and optional HEADING to change the section heading."
(when-let (((forge-db t))
(repo (forge-get-repository :tracked?))
(spec forge--buffer-topics-spec)
((memq (oref spec type) '(topic pullreq)))
(spec (clone spec)))
(spec (if sspec spec (clone forge--buffer-topics-spec)))
((memq (oref spec type) '(topic pullreq))))
(oset spec type 'pullreq)
(forge--insert-topics 'pullreqs "Pull requests"
(forge--insert-topics 'pullreqs
(or heading "Pull requests")
(forge--list-topics spec repo))))

(defun forge--insert-pullreq-commits (pullreq &optional all)
Expand Down
2 changes: 1 addition & 1 deletion lisp/forge-topic.el
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ can be selected from the start."
(defun forge--insert-topics (type heading topics)
(when topics
(let ((width (apply #'max (--map (length (oref it slug)) topics))))
(magit-insert-section ((eval type) nil t)
(magit-insert-section ((eval type) heading t)
(magit-insert-heading
(concat (magit--propertize-face (concat heading " ")
'magit-section-heading)
Expand Down

0 comments on commit f09d222

Please sign in to comment.