From d06363b393e5b1519b15f4123dd67c0f928259bf Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 10 Oct 2019 18:16:28 -0400 Subject: km/magit-github-url: Try origin URL if bug-reference URL is unset --- lisp/km-magit.el | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lisp/km-magit.el') diff --git a/lisp/km-magit.el b/lisp/km-magit.el index 2967c86..d83e9e1 100644 --- a/lisp/km-magit.el +++ b/lisp/km-magit.el @@ -810,7 +810,7 @@ function." ;;; GitHub links -(defun km/magit-github-url () +(defun km/magit-github-url-from-bugref () ;; `bug-reference-url-format' may be defined in an untracked ;; `.dir-locals.el`, so do this from the main worktree. (-when-let* ((wtree (caar (magit-list-worktrees))) @@ -823,6 +823,18 @@ function." (string-match "\\`https://github.com/[^/]+/[^/]+" url) (match-string 0 url)))) +(defun km/magit-github-url-from-origin () + (when-let ((origin (magit-get "remote.origin.url"))) + (and (string-match (rx "git@github.com:" + (group (one-or-more (not (any ".")))) + (zero-or-one ".git")) + origin) + (concat "https://github.com/" (match-string 1 origin))))) + +(defun km/magit-github-url () + (or (km/magit-github-url-from-bugref) + (km/magit-github-url-from-origin))) + (defun km/magit-github-file-link () (let ((ln (lambda (loc) (save-restriction -- cgit v1.2.3