From 107f6a60df317e9a7f1acbb0ccf99455516c8e04 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:32:25 +0000 Subject: [PATCH] refactor: stop adopting report comments from before v2.13 v2.13.0 added a marker to the PR comment. Comments posted before it were adopted by their title so the first run after an upgrade edited the old comment instead of posting a second one. That release is months old, so drop LEGACY_TITLES and match on the marker only. --- action/publish.py | 16 +++------------- tests/publish_test.py | 16 +++++++++------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/action/publish.py b/action/publish.py index 67972a1..5895a65 100644 --- a/action/publish.py +++ b/action/publish.py @@ -9,11 +9,6 @@ from action import cli, context, inputs, model, render -#: Prefixes of report bodies written by earlier versions, kept so the first run -#: after upgrading adopts the existing comment instead of posting a second one. -#: Drop these once a release has been out long enough. -LEGACY_TITLES = ("# Commit Check", "# Commit-Check") - #: The colour a label gets when the Action has to create it. AI_LABEL_COLOR = "8250df" @@ -142,18 +137,13 @@ def _find_own_comments(comments: list[Any]) -> tuple[Any | None, list[Any]]: Returns ``(target, stale)``. Only comments a bot posted with ``COMMENT_MARKER`` in them are ever edited or deleted: a person can paste - the marker too (quoting a report, say), and their comment is theirs. A comment from an earlier - version has no marker, so it is adopted (edited, which adds the marker) - when there is no marked comment yet, and only if a bot posted it: the - legacy signal is a title prefix, which a person can type by accident, and - editing someone's comment out from under them is not recoverable. + the marker too (quoting a report, say), and their comment is theirs. + A report from before v2.13.0 has no marker and is left as it is. """ marked = [c for c in comments if render.COMMENT_MARKER in c.body and _is_bot(c)] if marked: return marked[-1], marked[:-1] - - legacy = [c for c in comments if c.body.startswith(LEGACY_TITLES) and _is_bot(c)] - return (legacy[-1], []) if legacy else (None, []) + return None, [] def add_pr_comments(results: list[model.ScopeResult]) -> int: diff --git a/tests/publish_test.py b/tests/publish_test.py index de5d3a7..7780e0a 100644 --- a/tests/publish_test.py +++ b/tests/publish_test.py @@ -264,9 +264,9 @@ def test_creates_comment_with_rendered_body(self): self.assertIn("```diff\n@@ Commit 1/1 @@\n- bad message\n", body) def test_updates_existing_comment_when_changed(self): - # A report from an earlier version: no marker, and posted by the bot, - # which is what makes it safe to adopt. - old_comment = MagicMock(body="# Commit-Check ❌ 0 failures") + # The report an earlier run posted: the marker, and posted by the bot, + # which is what makes it safe to edit. + old_comment = MagicMock(body=f"{render.COMMENT_MARKER}\nold report") old_comment.user.type = "Bot" mock_pull_request = MagicMock() mock_pull_request.get_comments.return_value = [old_comment] @@ -664,10 +664,12 @@ def test_human_comment_with_the_old_title_is_not_adopted(self): self.assertIsNone(target) self.assertEqual(stale, []) - def test_bot_comment_from_an_older_version_is_adopted(self): + def test_bot_comment_without_the_marker_is_left_alone(self): + """A report from before v2.13.0 has no marker: it is neither edited + nor deleted, and the run posts a new comment.""" legacy = self._comment("# Commit-Check\nold report") target, stale = publish._find_own_comments([legacy]) - self.assertIs(target, legacy) + self.assertIsNone(target) self.assertEqual(stale, []) def test_human_comment_with_the_marker_is_never_touched(self): @@ -685,8 +687,8 @@ def test_no_comments_yields_nothing_to_update(self): def test_a_comment_without_an_author_is_not_a_bot(self): """A deleted account can leave ``user`` empty; that is not a crash, - and not a licence to adopt the comment either.""" - orphan = self._comment("# Commit Check\nold report") + and not a licence to edit the comment either.""" + orphan = self._comment(f"{render.COMMENT_MARKER}\nold report") orphan.user = None self.assertFalse(publish._is_bot(orphan)) self.assertEqual(publish._find_own_comments([orphan]), (None, []))