~grtcdr/liaison

66fe971bbb39fe382f97a8475027b66c5705cdb8 — grtcdr 1 year, 2 months ago f369641 permalink
Utilize permalinks to resolve edge case involving detached HEAD
2 files changed, 15 insertions(+), 14 deletions(-)

M TODO.org
M liaison.el
M TODO.org => TODO.org +1 -1
@@ 25,7 25,7 @@ one or two buffers and would then return =nil= for the rest.
** DONE Include a minimal reproducible example
** SCRATCHED Include a video demonstration of real-world example
* Bugs
** TODO Resolve edge case involving a detached HEAD state
** DONE Resolve edge case involving a detached HEAD state
I documented a workaround in the manual which addresses this issue. We
should however offer a more sturdy solution to avoid it altogether.
** DONE Inline commit logs returning empty string                     :help:

M liaison.el => liaison.el +14 -13
@@ 64,9 64,9 @@ build their resource URLs.")
	(setq forge (car f))))
    forge))

(defun liaison--get-branch ()
  "Return the name of the current branch."
  (car (vc-git-branches)))
(defun liaison--get-revision ()
  "Return the latest revision of the currently checked-out branch."
  (vc-git--rev-parse "HEAD"))

(defun liaison--get-remote (buffer)
  "Return the URL of this repository."


@@ 89,12 89,13 @@ build their resource URLs.")
instance. TYPE can be one of ’log’, ’tree’ or ’blob’."
  (unless (not (member type '(log tree blob)))
    (format-spec
     "%f/%t/branch/%b/%r"
     ;; FIX: map correctly
     "%f/%t/branch/%c/%r"
     `((?f . ,(concat "https://" (liaison--assoc-forge remote)))
       (?t . ,(cond ((eq type 'log) "log")
		    ((eq type 'tree) "src")
		    ((eq type 'blob) "plain")))
       (?b . ,(liaison--get-branch))
       (?c . ,(liaison--get-revision))
       (?r . ,(liaison--get-resource-slug (buffer-file-name)))))))

(defun liaison--build-gitea-resource-url (remote type)


@@ 103,7 104,7 @@ custom instance. TYPE can be one of ’log’, ’tree', ’blob’, or
’blame’."
  (unless (not (member type '(log tree blob blame)))
    (format-spec
     "%d/%s/%t/branch/%b/%r"
     "%d/%s/%t/commit/%c/%r"
     `((?d . ,(concat "https://" (liaison--assoc-forge remote)))
       (?s . ,(if (string-prefix-p "git@" remote)
		  (string-trim (car (cdr (split-string remote ":"))) nil ".git")


@@ 114,7 115,7 @@ custom instance. TYPE can be one of ’log’, ’tree', ’blob’, or
		    ((eq type 'tree) "src")
		    ((eq type 'blob) "raw")
		    ((eq type 'blame) "blame")))
       (?b . ,(liaison--get-branch))
       (?c . ,(liaison--get-revision))
       (?r . ,(liaison--get-resource-slug (buffer-file-name)))))))

(defun liaison--build-github-resource-url (remote type)


@@ 125,7 126,7 @@ GitHub. TYPE can be one of ’log’, ’edit’, ’blob’, ’plain’,
    (let* ((forge (if (eq type 'blob)
		      "https://raw.githubusercontent.com"
		    (concat "https://" (liaison--assoc-forge remote))))
	   (branch (liaison--get-branch))
	   (revision (liaison--get-revision))
	   (resource (liaison--get-resource-slug (buffer-file-name)))
	   (slug (if (string-prefix-p "git@" remote)
		     (string-trim (cadr (split-string remote ":")) nil ".git")


@@ 141,7 142,7 @@ GitHub. TYPE can be one of ’log’, ’edit’, ’blob’, ’plain’,
		       ((eq type 'blame) "blame")
		       ((or (eq type 'tree) (eq type 'plain)) "blob"))))
      (concat 
       (mapconcat 'identity (remove "" (list forge slug type branch resource)) "/")
       (mapconcat 'identity (remove "" (list forge slug type revision resource)) "/")
       plain-query-string))))

(defun liaison--build-gitlab-resource-url (remote type)


@@ 162,10 163,10 @@ custom instance. TYPE can be any one of ’log’, ’tree’, ’blob’ or
		     ((eq type 'plain) "blob")))
	   (plain-query-string (unless (not (eq type 'plain))
				 "?plain=1"))
	   (branch (liaison--get-branch))
	   (revision (liaison--get-revision))
	   (resource (liaison--get-resource-slug (buffer-file-name))))
      (concat
       (mapconcat 'identity (remove "" (list forge slug "-" type branch resource)) "/")
       (mapconcat 'identity (remove "" (list forge slug "-" type revision resource)) "/")
       plain-query-string))))

(defun liaison--build-sourcehut-resource-url (remote type)


@@ 179,9 180,9 @@ custom instance. TYPE can be any one of ’log’, ’tree’, ’blob’ or
		   (string-trim remote (concat "https://" (liaison--assoc-forge remote) "/"))))
	   (suffix (if (eq type 'blob) "" "item"))
	   (type (downcase (symbol-name type)))
	   (branch (liaison--get-branch))
	   (revision (liaison--get-revision))
	   (resource (liaison--get-resource-slug (buffer-file-name))))
      (mapconcat 'identity (remove "" (list forge slug type branch suffix resource)) "/"))))
      (mapconcat 'identity (remove "" (list forge slug type revision suffix resource)) "/"))))

(provide 'liaison)
;; liaison.el ends here