[Concept,5/7] patman: Improve patchwork project-finding

Message ID 20260214032632.3957279-6-sjg@u-boot.org
State New
Headers
Series patman: Improve series subcommand output |

Commit Message

Simon Glass Feb. 14, 2026, 3:26 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Some patchwork instances return project names with trailing whitespace,
which causes the exact string match to fail. Strip whitespace before
comparing.

Also add debug logging to show the projects being checked and which
one matches, to help diagnose future issues.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 tools/patman/control.py      |  2 +-
 tools/patman/cseries.py      | 13 +++++++++----
 tools/patman/test_cseries.py |  8 ++++----
 3 files changed, 14 insertions(+), 9 deletions(-)
  

Patch

diff --git a/tools/patman/control.py b/tools/patman/control.py
index 338a58f4d75..c6fede4305b 100644
--- a/tools/patman/control.py
+++ b/tools/patman/control.py
@@ -273,7 +273,7 @@  def patchwork(args, test_db=None, pwork=None):
             if not info:
                 raise ValueError("Project has not been set; use 'patman patchwork set-project'")
             name, pwid, link_name = info
-            print(f"Project '{name}' patchwork-ID {pwid} link-name {link_name}")
+            print(f"Project '{name}' patchwork-ID {pwid} link-name '{link_name}'")
         else:
             raise ValueError(f"Unknown patchwork subcommand '{args.subcmd}'")
     finally:
diff --git a/tools/patman/cseries.py b/tools/patman/cseries.py
index c5620985a09..e8d40394608 100644
--- a/tools/patman/cseries.py
+++ b/tools/patman/cseries.py
@@ -634,20 +634,25 @@  class Cseries(cser_helper.CseriesHelper):
             name (str): Name of the project to use in patchwork
             quiet (bool): True to skip writing the message
         """
+        tout.detail(f"Patchwork URL '{pwork.url}': finding name '{name}'")
         res = self.loop.run_until_complete(pwork.get_projects())
         proj_id = None
         link_name = None
         for proj in res:
-            if proj['name'] == name:
-                proj_id = proj['id']
+            pid, pname = proj['id'], proj['name']
+            ok = pname.strip() == name
+            tout.detail(f"{pid:3} '{pname}'")
+            if ok:
+                proj_id = pid
                 link_name = proj['link_name']
+                tout.detail(f'Name match: ID {proj_id}')
         if not proj_id:
             raise ValueError(f"Unknown project name '{name}'")
         self.db.settings_update(name, proj_id, link_name)
         self.commit()
         if not quiet:
-            tout.info(f"Project '{name}' patchwork-ID {proj_id} "
-                      f'link-name {link_name}')
+            tout.notice(f"Project '{name}' patchwork-ID {proj_id} "
+                        f"link-name '{link_name}'")
 
     def project_get(self):
         """Get the details of the project
diff --git a/tools/patman/test_cseries.py b/tools/patman/test_cseries.py
index a7750525ea6..3aa8e0e739e 100644
--- a/tools/patman/test_cseries.py
+++ b/tools/patman/test_cseries.py
@@ -2389,7 +2389,7 @@  Tested-by: Mary Smith <msmith@wibble.com>   # yak
         with terminal.capture() as (out, _):
             cser.project_set(pwork, 'U-Boot')
         self.assertEqual(
-            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name uboot",
+            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name 'uboot'",
             out.getvalue().strip())
 
     def test_patchwork_project_get(self):
@@ -2400,7 +2400,7 @@  Tested-by: Mary Smith <msmith@wibble.com>   # yak
         with terminal.capture() as (out, _):
             cser.project_set(pwork, 'U-Boot')
         self.assertEqual(
-            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name uboot",
+            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name 'uboot'",
             out.getvalue().strip())
 
         name, pwid, link_name = cser.project_get()
@@ -2419,7 +2419,7 @@  Tested-by: Mary Smith <msmith@wibble.com>   # yak
             self.run_args('-P', 'https://url', 'patchwork', 'set-project',
                           'U-Boot', pwork=pwork)
         self.assertEqual(
-            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name uboot",
+            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name 'uboot'",
             out.getvalue().strip())
 
         name, pwid, link_name = cser.project_get()
@@ -2430,7 +2430,7 @@  Tested-by: Mary Smith <msmith@wibble.com>   # yak
         with terminal.capture() as (out, _):
             self.run_args('-P', 'https://url', 'patchwork', 'get-project')
         self.assertEqual(
-            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name uboot",
+            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name 'uboot'",
             out.getvalue().strip())
 
     def check_series_list_patches(self):