]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow matching non-.git gitlab and gitea URLs in bug-reference
authorMiha Rihtaršič <miha@kamnitnik.top>
Tue, 26 Oct 2021 08:54:54 +0000 (10:54 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 27 Oct 2021 13:41:32 +0000 (15:41 +0200)
* lisp/progmodes/bug-reference.el
(bug-reference--build-forge-setup-entry): Allow matching non-.git
gitlab and gitea URLs, with and without slashes (bug#51316).

lisp/progmodes/bug-reference.el
test/lisp/progmodes/bug-reference-tests.el

index 993d670917b953f05f84499bb365454b643b6ac2..d7092a37d44efb1f01156d585359e14f5db58062 100644 (file)
@@ -287,7 +287,7 @@ via the internet it might also be http.")
 (cl-defmethod bug-reference--build-forge-setup-entry
   (host-domain (_forge-type (eql 'gitlab)) protocol)
   `(,(concat "[/@]" (regexp-quote host-domain)
-             "[/:]\\([.A-Za-z0-9_/-]+\\)\\.git")
+             "[/:]\\([.A-Za-z0-9_/-]+?\\)\\(?:\\.git\\)?/?\\'")
     "\\(\\([.A-Za-z0-9_/-]+\\)?\\([#!]\\)\\([0-9]+\\)\\)\\>"
     ,(lambda (groups)
        (let ((ns-project (nth 1 groups)))
@@ -304,7 +304,7 @@ via the internet it might also be http.")
 (cl-defmethod bug-reference--build-forge-setup-entry
   (host-domain (_forge-type (eql 'gitea)) protocol)
   `(,(concat "[/@]" (regexp-quote host-domain)
-             "[/:]\\([.A-Za-z0-9_/-]+\\)\\.git")
+             "[/:]\\([.A-Za-z0-9_/-]+?\\)\\(?:\\.git\\)?/?\\'")
     "\\(\\([.A-Za-z0-9_/-]+\\)?\\(?:#\\)\\([0-9]+\\)\\)\\>"
     ,(lambda (groups)
        (let ((ns-project (nth 1 groups)))
index 7a355509a1d40ba3c01bb5233dba825ddbd6385b..7a3ab5fbda0e0bf6e53ba60d00c5e3cb40dcb7ca 100644 (file)
 (require 'bug-reference)
 (require 'ert)
 
-(defun test--get-github-entry (protocol)
+(defun test--get-github-entry (url)
   (and (string-match
        (car (bug-reference--build-forge-setup-entry
-              "github.com" 'github protocol))
-        protocol)
-       (match-string 1 protocol)))
+              "github.com" 'github "https"))
+        url)
+       (match-string 1 url)))
+
+(defun test--get-gitlab-entry (url)
+  (and (string-match
+       (car (bug-reference--build-forge-setup-entry
+              "gitlab.com" 'gitlab "https"))
+        url)
+       (match-string 1 url)))
+
+(defun test--get-gitea-entry (url)
+  (and (string-match
+       (car (bug-reference--build-forge-setup-entry
+              "gitea.com" 'gitea "https"))
+        url)
+       (match-string 1 url)))
 
 (ert-deftest test-github-entry ()
   (should
     (test--get-github-entry "https://github.com/magit/magit/")
     "magit/magit")))
 
+(ert-deftest test-gitlab-entry ()
+  (should
+   (equal
+    (test--get-gitlab-entry "git@gitlab.com:larsmagne/csid.git")
+    "larsmagne/csid"))
+  (should
+   (equal
+    (test--get-gitlab-entry "git@gitlab.com:larsmagne/csid")
+    "larsmagne/csid"))
+  (should
+   (equal
+    (test--get-gitlab-entry "https://gitlab.com/magit/magit.git")
+    "magit/magit"))
+  (should
+   (equal
+    (test--get-gitlab-entry "https://gitlab.com/magit/magit.git/")
+    "magit/magit"))
+  (should
+   (equal
+    (test--get-gitlab-entry "https://gitlab.com/magit/magit")
+    "magit/magit"))
+  (should
+   (equal
+    (test--get-gitlab-entry "https://gitlab.com/magit/magit/")
+    "magit/magit")))
+
+(ert-deftest test-gitea-entry ()
+  (should
+   (equal
+    (test--get-gitea-entry "git@gitea.com:larsmagne/csid.git")
+    "larsmagne/csid"))
+  (should
+   (equal
+    (test--get-gitea-entry "git@gitea.com:larsmagne/csid")
+    "larsmagne/csid"))
+  (should
+   (equal
+    (test--get-gitea-entry "https://gitea.com/magit/magit.git")
+    "magit/magit"))
+  (should
+   (equal
+    (test--get-gitea-entry "https://gitea.com/magit/magit.git/")
+    "magit/magit"))
+  (should
+   (equal
+    (test--get-gitea-entry "https://gitea.com/magit/magit")
+    "magit/magit"))
+  (should
+   (equal
+    (test--get-gitea-entry "https://gitea.com/magit/magit/")
+    "magit/magit")))
+
 ;;; bug-reference-tests.el ends here