[Concept,21/37] patman: Fall back to database for patchwork link in status

Message ID 20260404213020.372253-22-sjg@u-boot.org
State New
Headers
Series patman: Autolink fixes and AI-assisted patch review |

Commit Message

Simon Glass April 4, 2026, 9:28 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

When 'patman status' cannot find a link for the current version in the
commit's Series-links tag, look it up in the database. This handles
the case where autolink runs without updating the commit, or the commit
has not yet been rewritten.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/patman/status.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
  

Patch

diff --git a/tools/patman/status.py b/tools/patman/status.py
index 8673eeb697e..205314aef3e 100644
--- a/tools/patman/status.py
+++ b/tools/patman/status.py
@@ -408,7 +408,26 @@  def find_link_and_show_status(series, branch, url, dest_branch, force,
     links = series.get('links')
     link = series.get_link_for_version(version, links)
     if not link:
-        raise ValueError(f'Series-links has no link for v{version}')
+        # Fall back to the database if the commit metadata does not
+        # have a link for this version (e.g. autolink ran without -u)
+        from patman import cseries
+
+        cser = cseries.Cseries()
+        try:
+            cser.open_database()
+            name, _ = patchstream.split_name_version(branch)
+            ser = cser.get_series_by_name(name)
+            if ser:
+                svinfo = cser.get_ser_ver(ser.idnum, version)
+                if svinfo:
+                    link = svinfo.link
+        except (ValueError, AttributeError):
+            pass
+        finally:
+            cser.close_database()
+    if not link:
+        raise ValueError(f'No patchwork link for v{version}; '
+                         'try: patman series autolink')
     tout.debug(f"Link '{link}")
 
     if 'patchwork_url' in series: