Function: forge--format-resource

forge--format-resource is a byte-compiled function defined in forge-core.el.

Signature

(forge--format-resource ARG &rest ARGS)

Implementations

(forge--format-resource (OBJECT forge-object) RESOURCE) in `forge-core.el'.

Return an API resource based on RESOURCE and slots of OBJECT. This is used by `forge--rest' and by extension `forge-rest'. RESOURCE is a string separated by slashes. Each part that begins with a colon is replaced with a value from OBJECT. `:repo' is a synonym for `:name'. `:project' is a like `:owner/:name', but the slash is quoted on Gitlab. `:topic' is a synonym for `:number' but only if OBJECT is a topic. Any other `:SLOT' means to use the value of that slot in OBJECT, or if that doesn't exist in its parent object (determined using `forge-get-parent').

Source Code

;; Defined in ~/.emacs.d/elpa/forge-20260408.1922/forge-core.el
(cl-defmethod forge--format-resource ((object forge-object) resource)
  "Return an API resource based on RESOURCE and slots of OBJECT.
This is used by `forge--rest' and by extension `forge-rest'.
RESOURCE is a string separated by slashes.  Each part that begins
with a colon is replaced with a value from OBJECT.  `:repo' is a
synonym for `:name'.  `:project' is a like `:owner/:name', but the
slash is quoted on Gitlab.  `:topic' is a synonym for `:number'
but only if OBJECT is a topic.  Any other `:SLOT' means to use
the value of that slot in OBJECT, or if that doesn't exist in its
parent object (determined using `forge-get-parent')."
  (save-match-data
    (setq resource
          (replace-regexp-in-string
           ":\\([^/]+\\)"
           (lambda (str)
             (let ((slot (intern (substring str 1))))
               (or (and$ (ignore-errors
                           (pcase slot
                             ('repo    (oref object name))
                             ('project (concat (string-replace
                                                "/" "%2F" (oref object owner))
                                               "%2F"
                                               (oref object name)))
                             ('topic   (and (forge--childp object 'forge-topic)
                                            (oref object number)))
                             (_        (eieio-oref object slot))))
                         (format "%s" $))
                   str)))
           resource t t))
    (cond-let
      ((not (string-match ":[^/]*" resource))
       resource)
      ([parent (ignore-errors (forge-get-parent object))]
       (forge--format-resource parent resource))
      ((error "Cannot resolve %s for a %s"
              (match-string 0 resource)
              (eieio-object-class object))))))