[Concept,09/11] patman: Record series send in the workflow table

Message ID 20260329150140.4095446-10-sjg@u-boot.org
State New
Headers
Series patman: Add workflow tracking for patch series |

Commit Message

Simon Glass March 29, 2026, 3:01 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

When a series is sent, record the event as a SENT workflow entry
and automatically create a TODO entry 7 days out so the developer
is reminded to follow up on reviews.

Sending again archives the previous entries and creates fresh ones.

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

 tools/patman/cseries.py      |  4 ++++
 tools/patman/test_cseries.py | 30 ++++++++++++++++++++++++++++++
 tools/patman/workflow.py     | 18 ++++++++++++++++++
 3 files changed, 52 insertions(+)
  

Patch

diff --git a/tools/patman/cseries.py b/tools/patman/cseries.py
index 8f159a8308f..4dddc70b679 100644
--- a/tools/patman/cseries.py
+++ b/tools/patman/cseries.py
@@ -20,6 +20,7 @@  from patman import cser_helper
 from patman.cser_helper import AUTOLINK, oid
 from patman import send
 from patman import status
+from patman import workflow
 
 
 class Cseries(cser_helper.CseriesHelper):
@@ -988,6 +989,9 @@  class Cseries(cser_helper.CseriesHelper):
         args.branch = self._get_branch_name(ser.name, version)
         likely_sent = send.send(args, git_dir=self.gitdir, cwd=self.topdir)
 
+        if likely_sent:
+            workflow.sent(self, ser.idnum)
+
         if likely_sent and autolink:
             tout.notice(f'Autolinking with Patchwork ({autolink_wait} seconds)')
             self.link_auto(pwork, name, version, True, wait_s=autolink_wait)
diff --git a/tools/patman/test_cseries.py b/tools/patman/test_cseries.py
index 8fcdbd340fb..01f4f4a133d 100644
--- a/tools/patman/test_cseries.py
+++ b/tools/patman/test_cseries.py
@@ -4293,3 +4293,33 @@  Date:   .*
         with terminal.capture() as (out, _):
             self.run_args('wf', 'todo-list')
         self.assertIn('No todos due', out.getvalue())
+
+    def test_workflow_sent(self):
+        """Test that sending a series creates SENT and TODO entries"""
+        cser = self.get_cser()
+        with terminal.capture():
+            cser.add('first', 'my description', allow_unmarked=True)
+
+        cser.fake_now = datetime(2025, 3, 1, 12, 0, 0)
+        ser = cser.get_series_by_name('first')
+
+        # Record a send
+        wf.sent(cser, ser.idnum)
+
+        # Should have a SENT entry with current time
+        ts = cser.db.workflow_get('sent', ser.idnum)
+        self.assertEqual('2025-03-01 12:00:00', ts)
+
+        # Should have a TODO entry 7 days out
+        ts = cser.db.workflow_get('todo', ser.idnum)
+        self.assertEqual('2025-03-08 12:00:00', ts)
+
+        # Sending again should archive old entries and create new ones
+        cser.fake_now = datetime(2025, 3, 5, 12, 0, 0)
+        wf.sent(cser, ser.idnum)
+
+        ts = cser.db.workflow_get('sent', ser.idnum)
+        self.assertEqual('2025-03-05 12:00:00', ts)
+
+        ts = cser.db.workflow_get('todo', ser.idnum)
+        self.assertEqual('2025-03-12 12:00:00', ts)
diff --git a/tools/patman/workflow.py b/tools/patman/workflow.py
index 029d63cf6a4..42e38db56f6 100644
--- a/tools/patman/workflow.py
+++ b/tools/patman/workflow.py
@@ -11,9 +11,27 @@  import enum
 
 class Wtype(enum.StrEnum):
     """Types of workflow entry"""
+    SENT = 'sent'
     TODO = 'todo'
 
 
+def sent(cser, series_id):
+    """Record that a series was sent and create a follow-up todo
+
+    Args:
+        cser (CseriesHelper): Series helper with open database
+        series_id (int): ID of the series that was sent
+    """
+    ts = cser.get_now().strftime('%Y-%m-%d %H:%M:%S')
+    cser.db.workflow_archive(Wtype.SENT, series_id)
+    cser.db.workflow_add(Wtype.SENT, series_id, ts)
+    when = cser.get_now() + timedelta(days=7)
+    todo_ts = when.strftime('%Y-%m-%d %H:%M:%S')
+    cser.db.workflow_archive(Wtype.TODO, series_id)
+    cser.db.workflow_add(Wtype.TODO, series_id, todo_ts)
+    cser.commit()
+
+
 def todo(cser, series, days):
     """Mark a series as a todo item after a number of days