emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Smart processing of http(s) links


From: Ag Ibragimov
Subject: Re: Smart processing of http(s) links
Date: Sun, 28 Jun 2020 16:59:13 -0700
User-agent: mu4e 1.4.10; emacs 28.0.50


Oh cool. This is exactly what I needed:

I was able to build this:

#+begin_src emacs-lisp
(defun get-gh-item-title (uri &optional include-number?)
 "Based on given github URI for (pull request or an issue),
 returns its title"
 (when (string-match "\\(github.com\\).*\\(issues\\|pull\\)" uri) ; either PR 
or issue
   (pcase-let* ((`(_ _ ,owner ,repo ,type ,number) (remove "" (split-string uri 
"/")))
                (gh-resource (format "/repos/%s/%s/%s/%s"
                                     owner
                                     repo
                                     (if (string= type "pull") "pulls" type)
                                     number))
                (resp (ghub-get gh-resource nil :auth 'forge)))
     (when resp
       (format "%s%s" (alist-get 'title resp)
               (when include-number? (format " #%s" number)))))))

(defun org-link-make-description-function* (link desc)
 (cond ((string-match "\\(github.com\\).*\\(issues\\|pull\\)" link)
        (get-gh-item-title link :with-number))
       (t desc)))

(setq org-link-make-description-function 'org-link-make-description-function*)
#+end_src

https://gist.github.com/agzam/b2f2d441acb96e1d693a2c81e9c4518f
On Sun 28 Jun 2020 at 14:02, Kyle Meyer <kyle@kyleam.com> wrote:

Ag Ibragimov writes:

Whenever I I use org-insert-link and it turns out to be a URI that
starts with "https://github.com"; I would like it to be processed
differently than any other link, one example - if it is a PR or a
Github Issue, I'd like it to fetch summary(title) of it and create a
link that looks like this:

[[https://github.com/user/repo/issues/3899][This issue needs to be fixed #3899]]

Do we have any "built-in" mechanism for doing something like this? Can
someone suggest how I can make it. Thank you!

You can set org-link-make-description-function to a function that
detects links of interest and generates a custom description.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]