Skip to content

YETUS-1280. Support updating or hiding prior GitHub PR comments - #405

Merged
ndimiduk merged 4 commits into
apache:mainfrom
pan3793:github-update-comment
Nov 30, 2026
Merged

ndimiduk merged 4 commits into
apache:mainfrom
pan3793:github-update-comment

Conversation

@pan3793

@pan3793 pan3793 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

https://issues.apache.org/jira/browse/YETUS-1280

--github-write-comment appends a new PR comment on every run. Add --github-comment-mode=<append|update|hide> (implies --github-write-comment) and --github-comment-key=<key> to avoid comment spam across rebuilds (applied to final report comments only; public github_write_comment callers remain append-only):

  1. append (default): appends a new PR comment on every run.
  2. update: edits the oldest visible report comment previously written by the token's user with the same key (PATCH /repos/{owner}/{repo}/issues/comments/{id}), and minimizes any extra visible duplicates as OUTDATED. Lookup or PATCH failures fall back to POST.
  3. hide: posts a new report comment and minimizes prior visible report comments written by the token's user with the same key as OUTDATED via GraphQL minimizeComment. Lookup or minimize failures log a warning without failing the run.
  4. update and hide tag reports with <!-- yetus-report:<key> -->, add a Tested commit row, identify the author via GET /user (or github-actions[bot] with a warning under GitHub Actions), ignore already-minimized comments, and skip commenting when the PR head has moved past the tested commit.

Tested with github_comment_mode.bats and end to end against real GitHub.

Assisted-by: Gemini 4 Neon

--github-update-comment[=<key>] implies --github-write-comment, and
updates the comment the token's user previously wrote with the same key
instead of adding a new one on every run. The report is skipped when
the PR head moved past the tested commit.

Assisted-by: Claude Opus 5.5
@pan3793

pan3793 commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

Tested end to end against real GitHub on pan3793/yetus-comment-test#1, running test-patch --robot --build-tool=nobuild --plugins=github,blanks GH:1 from this branch:

  1. First run with --github-update-comment=test posts one comment with the marker and a Tested commit row.
  2. Running again edits that comment in place.
  3. After a new push, the next run edits the same comment, and Tested commit shows the new sha.
  4. A different key (other) gets its own comment and updates only that one.
  5. Once the comment is hidden as outdated, the next run leaves it alone and posts a new one, which later runs then update.
  6. --github-write-comment alone still posts a new comment each run, with no marker or Tested commit row.

The marker does not show in the rendered comment. The stale-build skip is covered by github_update_comment.bats only.

@pan3793

pan3793 commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

cc @aw-was-here @ndimiduk, could you please take a look? The current Yetus report (post a new comment for each report) keeps spamming the PR and makes it too hard for reviewers to find the real review comment ...

@ndimiduk

ndimiduk commented Nov 6, 2026

Copy link
Copy Markdown
Member

ACK. I'll make time to take a look in the next couple days, if Allen doesn't beat me to it.

@pan3793

pan3793 commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

friendly ping @ndimiduk ~

@ndimiduk

Copy link
Copy Markdown
Member

So my preference is against editing an existing comment in place. I would rather than the automation hides the out-of-date comment and posts a new one. That way everyone gets a notification about the new activity and the history of results is available for those who are interested.

All that said, I'm not opposed to the plugin supporting either mode. I think there's good arguments for each depending on what checks are managed via Yetus.

@ndimiduk

Copy link
Copy Markdown
Member

Jogging my memory... I implemented the hide-and-post behavior in https://issues.apache.org/jira/browse/HBASE-28642 . It would be excellent if we could get both behaviors into Yetus as variants on a feature.

Replace --github-update-comment with --github-comment-mode=<append|update|hide>
and --github-comment-key=<key>. In hide mode, post a new comment and minimize
prior visible comments written by the same GitHub user with the same key via
GraphQL minimizeComment (classifier: OUTDATED).

Assisted-by: Gemini 4 Neon
@pan3793 pan3793 changed the title YETUS-1280. Support updating the GitHub PR comment in place YETUS-1280. Support updating or hiding prior GitHub PR comments Nov 30, 2026
@pan3793

pan3793 commented Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for the feedback and the pointer to HBASE-28642. Added both modes in 006c3b2 via --github-comment-mode=<append|update|hide> and --github-comment-key=<key> (sharing the hidden marker, author check, pagination, stale-build guard, and Tested commit row):

  1. update: edits the oldest visible matching comment in place.
  2. hide: posts a new comment and minimizes prior visible matching comments as OUTDATED via GraphQL minimizeComment.

Verified both modes end to end on pan3793/yetus-comment-test#1 (update edited 6653439607 in place; three hide runs with key hide-test kept only 7273045125 visible and minimized 7273025799 and 7273035232 as outdated).

@pan3793

pan3793 commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

also cc @cxzl25

@ndimiduk ndimiduk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few smaller items:

  • Token identity. GET /user isn't available to GitHub App installation tokens. Plain /user is missing from https://docs.github.com/en/rest/authentication/endpoints-available-for-github-app-installation-access-tokens. Outside GitHub Actions, an App token makes update and hide behave as append, with one warning per run. Under GitHub Actions with an App token passed as --github-token, the login silently becomes github-actions[bot], nothing matches, and nothing is logged (L985-988). Nothing gets written to the wrong comment. But "the mode isn't working" is invisible in this case, so a log line when the fallback login is assumed would help.

  • Silent list failure. A failed comment-list GET (L1020-1029) returns 1 with no log line. In update mode this is the quietest route to the duplicate described on L1167, and the run log looks the same as a first run.

  • Tests. A few behavior-changing mutations pass github_comment_mode.bats:

    • Making the id lookup print every match instead of only the oldest. The PATCH URL becomes comments/2<newline>3, which real curl rejects, but outcome() still reports PATCH:2.
    • Applying the github-actions[bot] fallback for every robot rather than only githubactions.
    • Treating a missing github-pull.json (empty tested sha) as superseded.

    Asserting exactly one PATCH to the expected id, a jenkins fixture with a github-actions[bot] comment that expects a POST, and a finalreport case without github-pull.json would cover these.

(LLM assisted)

rm "${restfile}"
return 0
fi
yetus_error "WARNING: Cannot update GitHub comment ${commentid}. Writing a new one."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In update mode, a single failed write leaves a second keyed comment that no later run touches. The trigger is any of: the PATCH failing (here), the comment-list GET failing (L1020-1029), or GET /user failing (L1014-1016). Each of these falls through to the POST. On the next run github_find_comments ... id again returns the oldest match (the awk print id; exit at L1047-1048 and the early return at L1057-1058), so the older comment keeps getting PATCHed. The newer one sits below it in the thread with a stale result for the rest of the PR's life. Nothing in the update branch looks at the other matches.

Reproduced with a stub curl: run 1 PATCHes comment 2, the PATCH fails, and it POSTs comment 3. Run 2, with comments 2 and 3 both visible, PATCHes comment 2 and leaves comment 3 as it was.

The hide branch already collects every visible match and minimizes it. Running that over the other matches after a successful PATCH would let update converge back to one visible report.

(LLM assisted)

@pan3793 pan3793 Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 45b08fd. github_find_comments collects all visible matching <id> <node_id> pairs across pages, and github_write_report_comment minimizes extra visible duplicates as OUTDATED after a successful PATCH in update mode.

return 0
fi

if github_comment_mode_active; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The marker is added for every caller of github_write_comment, not only the final report. write_comment in test-patch.sh sends the "(!) A patch to the testing environment has been detected. Re-executing..." note through this hook:

if [[ ${ROBOT} == true ]]; then
rm "${commentfile}" 2>/dev/null
echo "(!) A patch to the testing environment has been detected. " > "${commentfile}"
echo "Re-executing against the patched versions to perform further tests. " >> "${commentfile}"
echo "The console is at ${BUILD_URL}${BUILD_URL_CONSOLE} in case of problems." >> "${commentfile}"
write_comment "${commentfile}"

That fires under --robot when the PR touches the personality or the Dockerfile. In update mode the note replaces the previous report. If the re-executed run is aborted, or its final report is skipped because the head moved, the 3-line note stays as the only visible report until the next completed run. The interim path also bypasses the superseded check and the Tested commit row, both of which live in github_finalreport_as_comment. The docs (github.html.md L64) say only that "the report" carries the marker.

github_write_comment is @audience public / @stability stable. Keeping it append-only and applying the modes from github_finalreport_as_comment would avoid changing what other callers get.

(LLM assisted)

@pan3793 pan3793 Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 45b08fd. github_write_comment stays append-only for public callers, and update/hide handling lives in private github_write_report_comment invoked only by github_finalreport_as_comment.

Comment on lines +98 to +107
append)
GITHUB_COMMENT_MODE=append
;;
update|hide)
GITHUB_COMMENT_MODE=${i#*=}
GITHUB_WRITE_COMMENT=true
;;
*)
yetus_error "WARNING: Unknown --github-comment-mode '${i#*=}'. Using 'append'."
GITHUB_COMMENT_MODE=append

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

--github-comment-mode=append doesn't set GITHUB_WRITE_COMMENT, so on its own it posts nothing. Only update and hide turn commenting on. An unrecognized value, e.g. --github-comment-mode=Hide, logs "Using 'append'." and then also posts nothing, because the gate at L1493 is still false. The docs at github.html.md L52 pair --github-write-comment with (--github-comment-mode=append), which reads as if the two are equivalent.

Related: when only --github-comment-key is invalid (no mode given), the warning at L117 says "Writing a new comment instead." even though no comment is written unless --github-write-comment is also set.

(LLM assisted)

@pan3793 pan3793 Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 45b08fd. Every --github-comment-mode value (including append and unknown-mode fallback) enables GITHUB_WRITE_COMMENT, and the invalid --github-comment-key warning no longer assumes commenting is enabled.

1. Keep public github_write_comment append-only; apply update/hide modes
   only to final reports via github_write_report_comment.
2. Minimize duplicate visible comments after a successful PATCH in update
   mode so transient write failures converge back to one visible report.
3. Have all --github-comment-mode values (including append and fallback)
   enable GITHUB_WRITE_COMMENT, and clarify invalid key warning text.
4. Log warnings on comment-list GET failures and when assuming
   github-actions[bot] after /user lookup fails under GitHub Actions.
5. Tighten bats assertions and add tests for duplicate cleanup,
   non-report writes, missing github-pull.json, and non-GHA bot fallback.

Assisted-by: Gemini 4 Neon
@pan3793

pan3793 commented Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

Addressed all items in 45b08fd:

  1. Logged warnings when assuming github-actions[bot] after a failed /user lookup under GitHub Actions and when listing PR comments fails.
  2. Tightened github_comment_mode.bats (exact single-PATCH URL assertion, newline rejection in mock curl) and added tests for duplicate cleanup, append-only github_write_comment, non-GHA github-actions[bot] non-fallback, and missing github-pull.json.

@ndimiduk ndimiduk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, let's try it!

@ndimiduk

Copy link
Copy Markdown
Member

I'm not sure what's up with CI here. I assigned the Jira to you, set it as "patch available", and re-triggered the GHA run.

@pan3793

pan3793 commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

the ci seems broken for a while and irrelevant to this change

@ndimiduk
ndimiduk merged commit 310dfb8 into apache:main Nov 30, 2026
2 of 4 checks passed
@ndimiduk

Copy link
Copy Markdown
Member

I think you're right. Let me file that as a separate issue. Thanks for the contribution @pan3793 !

@ndimiduk

Copy link
Copy Markdown
Member

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.

2 participants