Skip to content

hide old range-diff comments on a force push - #13

Open
bc1cindy wants to merge 1 commit into
mainfrom
hide-outdated
Open

bc1cindy wants to merge 1 commit into
mainfrom
hide-outdated

Conversation

@bc1cindy

@bc1cindy bc1cindy commented Oct 8, 2026

Copy link
Copy Markdown
Member

closes #3: on a force push, earlier range-diff comments at least hide-after-days old (three by default) are hidden as outdated.

@bc1cindy

bc1cindy commented Oct 8, 2026 •

Copy link
Copy Markdown
Member Author

tested in #14 with hide-after-days 0

Captura de Tela 2026-10-08 às 15 01 28

@bc1cindy
bc1cindy added this pull request to stack #12 October 8, 2026 17:59
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@oakagent

Copy link
Copy Markdown

ACK dd4d856 (automated): reviewed 1 commit dd4d856; no findings.

@yuval-block yuval-block left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code ACK but i'm not 100% sure about concept ACK, I opened the issue this closes based on a hunch that this would become annoying so seeking concept ACK from other contributors to the project (@arminsabouri ?). the hide-after-days and its default value in particular makes sense to me.

an alternative approach would be to update the initial comment but i think i prefer this approach even though it's more spammy because it clarifies the chronology.

@github-actions

Copy link
Copy Markdown
range-diff for force push dd4d856d15 → 8b0baeca96 October 19, 2026 22:23 UTC: 1 unchanged; 1 commit; base db1484fe10 → 4070ea4ef8 (diverged, 5 ahead and 3 behind)

reproduce: git range-diff db1484f..dd4d856 4070ea4..8b0baec

1:  dd4d856d15 +158 -8 7f = 1:  8b0baeca96 +158 -8 7f Hide old range-diff comments on a force push

@github-actions

Copy link
Copy Markdown
range-diff for force push 8b0baeca96 → 51dc3fc2a6 October 19, 2026 22:26 UTC: 1 unchanged; 1 commit; base 4070ea4ef8 → 82dca2948a (diverged, 2 ahead and 1 behind)

reproduce: git range-diff 4070ea4..8b0baec 82dca29..51dc3fc

1:  8b0baeca96 +158 -8 7f = 1:  51dc3fc2a6 +158 -8 7f Hide old range-diff comments on a force push

Base automatically changed from diffstat to main October 19, 2026 22:27
@github-actions

Copy link
Copy Markdown
range-diff for force push 51dc3fc2a6 → d743ce0463 October 19, 2026 22:28 UTC: 1 unchanged; 1 commit; base 82dca2948a → 2b82922ab1 (descendant, 1 commit ahead)

reproduce: git range-diff 82dca29..51dc3fc 2b82922..d743ce0

1:  51dc3fc2a6 +158 -8 7f = 1:  d743ce0463 +158 -8 7f Hide old range-diff comments on a force push

Comment thread post-range-diff-comment.sh Resolved
Earlier range-diff comments at least hide-after-days old (three by
default) are minimized as outdated, so a long pull request stays readable.
@github-actions

Copy link
Copy Markdown
range-diff for force push d743ce0463 → 39bceb106f October 20, 2026 03:30 UTC: 1 modified; 1 commit; same base 2b82922ab1

reproduce: git range-diff 2b82922..d743ce0 2b82922..39bceb1

1:  d743ce0463 +158  -8 7f ! 1:  39bceb106f +175 -11 7f Hide old range-diff comments on a force push
1: d743ce0463 ! 1: 39bceb106f Hide old range-diff comments on a force push
@@ post-range-diff-comment.sh: if [[ ${POST_COMMENT:-true} == false ]]; then
  fi
  
  : "${GH_TOKEN:?}"
+-if ! url="$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" \
+-  -F body=@"$WORK/comment.md" --jq .html_url)"; then
 +hide_outdated() {
 +  local ids id
 +  # shellcheck disable=SC2016
@@ post-range-diff-comment.sh: if [[ ${POST_COMMENT:-true} == false ]]; then
 +      }' --jq '.data.repository.pullRequest.comments.nodes[]' |
 +    python3 "$HERE/outdated.py" "$HIDE_AFTER_DAYS")" || return
 +  for id in $ids; do
++    [[ $id == "$1" ]] && continue
 +    # shellcheck disable=SC2016
 +    gh api graphql -f id="$id" -f query='
 +      mutation($id: ID!) {
@@ post-range-diff-comment.sh: if [[ ${POST_COMMENT:-true} == false ]]; then
 +      }' >/dev/null || return
 +  done
 +}
-+# Before posting, so the comment for this push is never among them.
-+if [[ -n ${HIDE_AFTER_DAYS:-} ]] && ! hide_outdated; then
-+  echo "::warning::could not hide the outdated range-diff comments"
-+fi
 +
- if ! url="$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" \
-   -F body=@"$WORK/comment.md" --jq .html_url)"; then
++if ! posted="$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" \
++  -F body=@"$WORK/comment.md" --jq '"\(.node_id) \(.html_url)"')"; then
    echo "::error::could not post the comment; the token needs pull-requests: write" \
+     "(pull_request events from forks only get a read-only token)"
+   exit 1
+ fi
++read -r node_id url <<<"$posted"
+ echo "comment-url=$url" >>"$OUT"
+ echo "posted $url"
++
++# After posting, so a failed post never leaves the old ones hidden.
++if [[ -n ${HIDE_AFTER_DAYS:-} ]] && ! hide_outdated "$node_id"; then
++  echo "::warning::could not hide the outdated range-diff comments"
++fi
 
  ## tests/test_action.py ##
 @@
@@ tests/test_action.py: class ActionTest(unittest.TestCase):
          base_ref="main",
          rewound=(),
 +        comments=None,
++        post_fails=False,
      ):
 -        # Stands in for the activity log: prints the old tips of the base branch.
 +        # Stands in for GitHub: the old tips of the base branch, the comments
@@ tests/test_action.py: class ActionTest(unittest.TestCase):
 +        (stub / "comments").write_text(
 +            "".join(json.dumps(c) + "\n" for c in comments or ())
 +        )
++        post = "exit 1" if post_fails else f"echo NEW {COMMENT_URL}"
          gh = stub / "gh"
 -        gh.write_text("#!/bin/sh\n" + "".join(f"echo {tip}\n" for tip in rewound))
 +        gh.write_text(f"""#!/bin/sh
@@ tests/test_action.py: class ActionTest(unittest.TestCase):
 +*minimizeComment*) echo "$*" >>"{stub}/hidden" ;;
 +*graphql*) cat "{stub}/comments" ;;
 +*/activity*) printf '%s\\n' {" ".join(rewound)} ;;
-+*) echo {COMMENT_URL} ;;
++*) {post} ;;
 +esac
 +""")
          gh.chmod(0o755)
@@ tests/test_action.py: class ActionTest(unittest.TestCase):
          )
          command = (
 @@ tests/test_action.py: class ActionTest(unittest.TestCase):
+             timeout=20,
+             check=False,
          )
-         self.assertEqual(result.returncode, 0, result.stderr)
+-        self.assertEqual(result.returncode, 0, result.stderr)
++        self.assertEqual(result.returncode, int(post_fails), result.stderr)
          self.assertTrue(output.exists(), result.stderr)
 -        self.assertEqual(output.read_text(), f"forced={str(forced).lower()}\n")
 -        if forced:
-+        posted = f"comment-url={COMMENT_URL}\n" if posting else ""
++        posted = f"comment-url={COMMENT_URL}\n" if posting and not post_fails else ""
 +        self.assertEqual(output.read_text(), f"forced={str(forced).lower()}\n{posted}")
 +        if not forced:
 +            self.assertFalse(summary.exists())
@@ tests/test_action.py: class ActionTest(unittest.TestCase):
 +        hidden = (self.root / "stub" / "hidden").read_text()
 +        self.assertIn("id=OLD", hidden)
 +        self.assertNotIn("id=NEW", hidden)
++
++    def test_the_posted_comment_is_never_hidden(self):
++        self.run_action(comments=[comment("NEW", "2000-01-01T00:00:00Z")])
++        self.assertFalse((self.root / "stub" / "hidden").exists())
++
++    def test_a_failed_post_hides_nothing(self):
++        old = comment("OLD", "2000-01-01T00:00:00Z")
++        self.run_action(comments=[old], post_fails=True)
++        self.assertFalse((self.root / "stub" / "hidden").exists())
 +
      def test_force_push_shallow_checkout(self):
          self.run_action(shallow=True)

@oakagent

Copy link
Copy Markdown

ACK 39bceb1

oak · automated · 39bceb1 · 1 commit · 0 findings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

automatically hide previous comments as outdated

3 participants