all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>, Tassilo Horn <tsdh@gnu.org>
Cc: 51316@debbugs.gnu.org
Subject: bug#51316: 29.0.50; Should we match the final ".git" in bug-reference autosetup?
Date: Tue, 26 Oct 2021 11:01:03 +0200	[thread overview]
Message-ID: <87ilxkcg8g.fsf@miha-pc> (raw)
In-Reply-To: <87o87ebos4.fsf@gnus.org>


[-- Attachment #1.1: Type: text/plain, Size: 526 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Tassilo Horn <tsdh@gnu.org> writes:
>
>> With the reasoning above, I'd suggest using
>>
>>   "[/:]\\([.A-Za-z0-9_/-]+?\\)\\(?:\\.git/?\\)?\\'"
>
> Doesn't match "https://github.com/emacs-mirror/emacs/", which is what this
> bug report was originally about, sort of.  So I've now added a test for
> this and altered the regexp to pass the test (on the trunk).

Thanks. It works now for github URLs, but it should probably be used for
gitlab and gitea URLs as well, patch attached.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Allow-matching-non-.git-gitlab-and-gitea-URLs-in-bug.patch --]
[-- Type: text/x-patch, Size: 4463 bytes --]

From d75c466580a5a1d6242d77d1820f6d7aa0ec4895 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <miha@kamnitnik.top>
Date: Tue, 26 Oct 2021 10:54:54 +0200
Subject: [PATCH] Allow matching non-.git gitlab and gitea URLs in
 bug-reference

* 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            |  4 +-
 test/lisp/progmodes/bug-reference-tests.el | 74 ++++++++++++++++++++--
 2 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/bug-reference.el b/lisp/progmodes/bug-reference.el
index 993d670917..d7092a37d4 100644
--- a/lisp/progmodes/bug-reference.el
+++ b/lisp/progmodes/bug-reference.el
@@ -287,7 +287,7 @@ bug-reference--build-forge-setup-entry
 (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 @@ bug-reference--build-forge-setup-entry
 (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)))
diff --git a/test/lisp/progmodes/bug-reference-tests.el b/test/lisp/progmodes/bug-reference-tests.el
index 7a355509a1..7a3ab5fbda 100644
--- a/test/lisp/progmodes/bug-reference-tests.el
+++ b/test/lisp/progmodes/bug-reference-tests.el
@@ -26,12 +26,26 @@
 (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
@@ -59,4 +73,56 @@ test-github-entry
     (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
-- 
2.33.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

  reply	other threads:[~2021-10-26  9:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 12:18 bug#51316: 29.0.50; Should we match the final ".git" in bug-reference autosetup? miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-22 14:59 ` Lars Ingebrigtsen
2021-10-22 20:45   ` Tassilo Horn
2021-10-22 21:42     ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-23  9:12       ` Tassilo Horn
2021-10-23 12:58         ` Gregory Heytings
2021-10-24 12:17     ` Lars Ingebrigtsen
2021-10-26  9:01       ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-10-27 13:02         ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ilxkcg8g.fsf@miha-pc \
    --to=bug-gnu-emacs@gnu.org \
    --cc=51316@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=miha@kamnitnik.top \
    --cc=tsdh@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.