diff --git a/README.md b/README.md index e3a0c99..5558e95 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,9 @@ changes. The summary line says how many commits the series had before and after, and whether its base is the same, a descendant or an ancestor of the old one, or diverged from it. A base branch that was itself rewritten, as a parent in a stack, is recognized from its force pushes in the repository's -activity log. Inputs and outputs are described in [action.yml](action.yml). +activity log. Range-diff comments at least three days old are hidden as +outdated on the next force push; `hide-after-days` changes or disables that. +Inputs and outputs are described in [action.yml](action.yml). `pull_request_target` gives fork PRs a token that can comment. It is safe here because nothing from the PR runs: the checkout is the base branch, the action diff --git a/action.yml b/action.yml index 0d9d212..c4f126e 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,9 @@ inputs: max-comment-bytes: description: "Interdiffs are truncated to keep the comment under this size; GitHub's limit is 65536." default: "65000" + hide-after-days: + description: "On a force push, hide as outdated the earlier range-diff comments that are at least this many days old; empty keeps them all." + default: "3" post-comment: description: Set to `false` to render the comment to the log and job summary without posting it. default: "true" @@ -51,4 +54,5 @@ runs: CREATION_FACTOR: ${{ inputs.creation-factor }} MAX_COMMENT_BYTES: ${{ inputs.max-comment-bytes }} POST_COMMENT: ${{ inputs.post-comment }} + HIDE_AFTER_DAYS: ${{ inputs.hide-after-days }} run: bash "$GITHUB_ACTION_PATH/post-range-diff-comment.sh" diff --git a/nix/package.nix b/nix/package.nix index f97acc1..71b4efa 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -6,6 +6,7 @@ mkdir -p "$out" cp ${../post-range-diff-comment.sh} "$out/post-range-diff-comment.sh" cp ${../render.py} "$out/render.py" + cp ${../outdated.py} "$out/outdated.py" ''; in { diff --git a/outdated.py b/outdated.py new file mode 100755 index 0000000..993d09f --- /dev/null +++ b/outdated.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +"""Pick the range-diff comments old enough to hide. + +Reads one GraphQL comment node per line and prints the ids to minimize. +""" + +from __future__ import annotations + +import json +import sys +from datetime import datetime, timedelta, timezone + +MARKER = "\n
", + } | changed + + +class OutdatedTest(unittest.TestCase): + def pick(self, *comments): + return outdated.outdated(list(comments), now=NOW, days=3) + + def test_age(self): + picked = self.pick( + comment("old", "2026-10-01T00:00:00Z"), + comment("just old enough", "2026-10-05T12:00:00Z"), + comment("recent", "2026-10-05T12:00:01Z"), + ) + self.assertEqual(picked, ["old", "just old enough"]) + + def test_only_its_own_visible_range_diffs(self): + old = "2026-10-01T00:00:00Z" + picked = self.pick( + comment("someone else's", old, viewerDidAuthor=False), + comment("another comment", old, body="looks good"), + comment("already hidden", old, isMinimized=True), + ) + self.assertEqual(picked, []) + + +if __name__ == "__main__": + unittest.main()