Function: forge--list-topics-2

forge--list-topics-2 is a byte-compiled function defined in forge-topic.el.

Signature

(forge--list-topics-2 SPEC REPO TYPE)

Source Code

;; Defined in ~/.emacs.d/elpa/forge-20260408.1922/forge-topic.el
(defun forge--list-topics-2 (spec repo type)
  (pcase-let (((eieio active state status category milestone labels marks
                      saved author assignee reviewer global order limit)
               spec))
    (cond (active
           (setq state 'open)
           (setq status '(unread pending)))
          ((eq status 'inbox)
           (setq status '(unread pending))))
    (when (eq state 'closed)
      (setq state '( completed merged unplanned duplicate outdated rejected)))
    `[:select :distinct topic:*
      :from [(as ,type topic)]
      ,@(pcase type
          ((and 'discussion (guard category))
           `[:join discussion-category :on (= discussion-category:name ,category)])
          ((and (or 'issue 'pullreq) (guard milestone))
           `[:join milestone :on (= milestone:title ,milestone)]))
      ,@(pcase (and labels type)
          ('discussion
           [:join discussion-label :on (= discussion-label:discussion  topic:id)
            :join            label :on (= label:id          discussion-label:id)])
          ('issue
           [:join      issue-label :on (= issue-label:issue            topic:id)
            :join            label :on (= label:id               issue-label:id)])
          ('pullreq
           [:join    pullreq-label :on (= pullreq-label:pullreq        topic:id)
            :join            label :on (= label:id             pullreq-label:id)]))
      ,@(pcase (and marks type)
          ('discussion
           [:join discussion-mark :on (= discussion-mark:discussion  topic:id)
            :join            mark :on (= mark:id           discussion-mark:id)])
          ('issue
           [:join      issue-mark :on (= issue-mark:issue            topic:id)
            :join            mark :on (= mark:id                issue-mark:id)])
          ('pullreq
           [:join    pullreq-mark :on (= pullreq-mark:pullreq        topic:id)
            :join            mark :on (= mark:id              pullreq-mark:id)]))
      ,@(pcase (and assignee type)
          ('issue
           [:join      issue-assignee :on (= issue-assignee:issue            topic:id)
            :join            assignee :on (= assignee:id            issue-assignee:id)])
          ('pullreq
           [:join    pullreq-assignee :on (= pullreq-assignee:pullreq        topic:id)
            :join            assignee :on (= assignee:id          pullreq-assignee:id)]))
      ,@(and reviewer
             [:join (as pullreq-review-request r) :on (= r:pullreq  topic:id)
              :join assignee                      :on (= assignee:id    r:id)])
      :where
      (and
       ,@(and (not global) repo `((= topic:repository ,(oref repo id))))
       ,@(cond
           ((and active state status)
            `((or (in topic:state  ,(vconcat (ensure-list state)))
                  (in topic:status ,(vconcat (ensure-list status))))))
           (`(,@(and state  `((in topic:state  ,(vconcat (ensure-list state)))))
              ,@(and status `((in topic:status ,(vconcat (ensure-list status))))))))
       ,@(pcase type
           ((and 'discussion (guard category))
            '((= topic:category discussion-category:id)))
           ((and (or 'issue 'pullreq) (guard milestone))
            '((= topic:milestone milestone:id))))
       ,@(and labels    `((or ,@(mapcar (##`(= label:name ,%)) labels))))
       ,@(and marks     `((or ,@(mapcar (##`(=  mark:name ,%))  marks))))
       ,@(and saved     '((= topic:saved-p  't)))
       ,@(and author    `((= topic:author   ,author)))
       ,@(and assignee (memq type '(issue pullreq))
              `((= assignee:login ,assignee)))
       ,@(and reviewer (eq type 'pullreq)
              `((= assignee:login ,reviewer))))
      :order-by [,(pcase order
                    ('newest            '(desc topic:number))
                    ('oldest            '(asc  topic:number))
                    ('recently-updated  '(desc topic:updated))
                    ('anciently-updated '(asc  topic:updated)))]
      ,@(and limit `(:limit ,limit))]))