diff mbox series

[v2] Improve pull request URL matching regex

Message ID 20191116161600.tktwrbe6tllb3e4r@chatter.i7.local
State Accepted
Headers show
Series [v2] Improve pull request URL matching regex | expand

Commit Message

Konstantin Ryabitsev Nov. 16, 2019, 4:16 p.m. UTC
When git-request-pull output is pasted into a mail client instead of
mailed directly, the ref part of the pull URL may end up wrapped to the
next line.

Example: https://lore.kernel.org/r/294422a4-37b2-def5-5d32-8988f27c3a5b@gmail.com/

This change properly parses URLs both with and without newlines.

Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
---
 patchwork/parser.py                           |  4 +-
 .../0023-git-pull-request-newline-in-url.mbox | 48 +++++++++++++++++++
 patchwork/tests/test_parser.py                |  9 ++++
 3 files changed, 59 insertions(+), 2 deletions(-)
 create mode 100644 patchwork/tests/mail/0023-git-pull-request-newline-in-url.mbox


base-commit: 239fbd2ca1bf140bc61fdee922944624b23c812c

Comments

Andrew Donnellan Nov. 19, 2019, 12:41 a.m. UTC | #1
On 17/11/19 3:16 am, Konstantin Ryabitsev wrote:
> When git-request-pull output is pasted into a mail client instead of
> mailed directly, the ref part of the pull URL may end up wrapped to the
> next line.
> 
> Example: https://lore.kernel.org/r/294422a4-37b2-def5-5d32-8988f27c3a5b@gmail.com/
> 
> This change properly parses URLs both with and without newlines.
> 
> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>

Thanks!

Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com>
Stephen Finucane Nov. 30, 2019, 2:44 p.m. UTC | #2
On Sat, 2019-11-16 at 11:16 -0500, Konstantin Ryabitsev wrote:
> When git-request-pull output is pasted into a mail client instead of
> mailed directly, the ref part of the pull URL may end up wrapped to the
> next line.
> 
> Example: https://lore.kernel.org/r/294422a4-37b2-def5-5d32-8988f27c3a5b@gmail.com/
> 
> This change properly parses URLs both with and without newlines.
> 
> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>

LGTM. Applied and will backport shortly.

Reviewed-by: Stephen Finucane <stephen@that.guru>
diff mbox series

Patch

diff --git a/patchwork/parser.py b/patchwork/parser.py
index c794f09..d25c0df 100644
--- a/patchwork/parser.py
+++ b/patchwork/parser.py
@@ -939,11 +939,11 @@  def parse_patch(content):
 def parse_pull_request(content):
     git_re = re.compile(r'^The following changes since commit.*'
                         r'^are available in the git repository at:\n'
-                        r'^\s*([\S]+://[^\n]+)$',
+                        r'^\s*([\w+-]+(?:://|@)[\w/.@:~-]+[\s\\]*[\w/._-]*)\s*$',
                         re.DOTALL | re.MULTILINE | re.IGNORECASE)
     match = git_re.search(content)
     if match:
-        return match.group(1)
+        return re.sub('\s+', ' ', match.group(1)).strip()
     return None
 
 
diff --git a/patchwork/tests/mail/0023-git-pull-request-newline-in-url.mbox b/patchwork/tests/mail/0023-git-pull-request-newline-in-url.mbox
new file mode 100644
index 0000000..74c29ce
--- /dev/null
+++ b/patchwork/tests/mail/0023-git-pull-request-newline-in-url.mbox
@@ -0,0 +1,48 @@ 
+From mboxrd@z Thu Jan  1 00:00:00 1970
+To: soc@kernel.org
+From: Matthias Brugger <matthias.bgg@gmail.com>
+Subject: [GIT PULL] soc: updates for v5.5
+Message-ID: <294422a4-37b2-def5-5d32-8988f27c3a5b@gmail.com>
+Date: Mon, 11 Nov 2019 13:23:51 +0100
+
+Hi Olof and Arnd,
+
+Please have a look on the following updates of drivers/soc for v5.5
+
+Thanks a lot,
+Matthias
+
+---
+
+The following changes since commit 54ecb8f7028c5eb3d740bb82b0f1d90f2df63c5c:
+
+  Linux 5.4-rc1 (2019-09-30 10:35:40 -0700)
+
+are available in the Git repository at:
+
+  https://git.kernel.org/pub/scm/linux/kernel/git/matthias.bgg/linux.git/
+tags/v5.4-next-soc
+
+for you to fetch changes up to 662c9d55c5ccb37f3920ecab9720f2ebf2a6ca18:
+
+  soc: mediatek: Refactor bus protection control (2019-11-07 10:11:04 +0100)
+
+----------------------------------------------------------------
+refactor code of mtk-scpsys
+
+----------------------------------------------------------------
+Weiyi Lu (5):
+      soc: mediatek: Refactor polling timeout and documentation
+      soc: mediatek: Refactor regulator control
+      soc: mediatek: Refactor clock control
+      soc: mediatek: Refactor sram control
+      soc: mediatek: Refactor bus protection control
+
+ drivers/soc/mediatek/mtk-scpsys.c | 214 ++++++++++++++++++++++++++------------
+ 1 file changed, 146 insertions(+), 68 deletions(-)
+
+_______________________________________________
+linux-arm-kernel mailing list
+linux-arm-kernel@lists.infradead.org
+http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
+
diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py
index 85c6c52..0bf7158 100644
--- a/patchwork/tests/test_parser.py
+++ b/patchwork/tests/test_parser.py
@@ -630,6 +630,15 @@  class PatchParseTest(PatchTest):
             diff.startswith('diff --git a/arch/x86/include/asm/smp.h'),
             diff)
 
+    def test_git_pull_newline_in_url(self):
+        diff, message = self._find_content(
+            '0023-git-pull-request-newline-in-url.mbox')
+        pull_url = parse_pull_request(message)
+        self.assertEqual(
+            'https://git.kernel.org/pub/scm/linux/kernel/git/matthias.bgg/'
+            'linux.git/ tags/v5.4-next-soc',
+            pull_url)
+
     def test_git_rename(self):
         diff, _ = self._find_content('0008-git-rename.mbox')
         self.assertTrue(diff is not None)