Skip to content

Commit

Permalink
Improve kludge to support unsecured hosts
Browse files Browse the repository at this point in the history
All that is necessary now is that users add the host to
`ghub-insecure-hosts'.  Defining a separate repository class is no
longer necessary.

Preserve support for the previous iteration of the kludge in
`forge--ghub-type-symbol'.  Not doing this would mean that users would
have to change the value of the class row of affected repositories in
the database, in addition to removing an entry from `forge-alist'.

Change the key that is looked up in `forge-alist' from GITHOST to
WEBHOST.  Since these formats are used for web and api urls, but not
git urls, it makes no sense to use the GITHOST as key.  The WEBHOST
and GITHOST are usually equal, but there is a small change that they
are not for some affected instances.

See #651 and #9.
  • Loading branch information
tarsius committed Mar 28, 2024
1 parent 2a3b41e commit 9f152cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions lisp/forge-repo.el
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,17 @@ forges and hosts."
(user-error "Cannot determine apihost for %S" host)))

(cl-defmethod forge--format ((repo forge-repository) format-or-slot &optional spec)
(format-spec
(if (symbolp format-or-slot)
(eieio-oref repo format-or-slot)
format-or-slot)
(pcase-let* (((eieio forge owner name) repo)
(path (if owner (concat owner "/" name) name)))
(pcase-let* (((eieio (forge webhost) owner name) repo)
(path (if owner (concat owner "/" name) name)))
(format-spec
(let ((format (if (symbolp format-or-slot)
(eieio-oref repo format-or-slot)
format-or-slot)))
(if (member webhost ghub-insecure-hosts)
(replace-regexp-in-string "\\`https://" "http://" format t t)
format))
`(,@spec
(?h . ,forge) ;aka webhost
(?h . ,webhost)
(?o . ,owner)
(?n . ,name)
(?p . ,path)
Expand Down Expand Up @@ -476,9 +479,11 @@ forges and hosts."
(defun forge--ghub-type-symbol (class)
(pcase-exhaustive class
;; This package does not define a `forge-gitlab-http-repository'
;; class, but we suggest at #9 that users define such a class if
;; they must connect to a Gitlab instance that uses http instead
;; of https.
;; class, but we used to suggest at #9 that users define such a class
;; if they must connect to a Gitlab instance that uses http instead
;; of https. Doing that isn't necessary anymore, but we have to keep
;; supporting it here. It is now sufficient to add an entry to
;; `ghub-insecure-hosts'.
((or 'forge-gitlab-repository 'forge-gitlab-http-repository) 'gitlab)
('forge-github-repository 'github)
('forge-gitea-repository 'gitea)
Expand Down
2 changes: 1 addition & 1 deletion lisp/forge-topic.el
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ Return a value between 0 and 1."
(defun forge--markdown-translate-filename-function (file)
(if (string-match-p "\\`https?://" file)
file
(let ((host (oref (forge-get-repository :tracked) githost)))
(let ((host (oref (forge-get-repository :tracked) forge))) ;aka webhost
(concat (if (member host ghub-insecure-hosts) "http://" "https://")
host
(and (not (string-prefix-p "/" file)) "/")
Expand Down

0 comments on commit 9f152cf

Please sign in to comment.