-
-
Notifications
You must be signed in to change notification settings - Fork 1
ci: sync Antigravity reviewer to the fixed comment-selection version #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+242
−31
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # agy-review-selftest.sh -- guards the comment-selection logic in `agy-review.sh`. | ||
| # | ||
| # Why this exists: that filter decides which PR comments the bot DELETES, and it has been wrong | ||
| # twice, both times invisibly. | ||
| # | ||
| # 1. The just-posted comment was not reliably excluded. `new_comment_id` came from re-querying | ||
| # the comment list, which races GitHub's read replication; on a miss the exclusion became | ||
| # `select(.id != null)`, true for every id, and the run deleted the review it had just | ||
| # published. | ||
| # 2. jq's `--arg`/`--argjson` were handed to `gh api`, which has no such flags. It exited | ||
| # non-zero, `2>/dev/null` hid the message, and `set -o pipefail` + `set -e` killed the script | ||
| # AFTER posting — so stale comments silently accumulated and the job went red with nothing in | ||
| # the log explaining why. | ||
| # | ||
| # Neither was catchable by looking at the review the bot posted: both times it posted fine. So the | ||
| # filter is tested here directly, offline, against fixtures — no network, no `gh`, no runner. | ||
| # | ||
| # Run: bash scripts/agy-review-selftest.sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| # Source the constants out of the reviewer without running it. `agy-review.sh` does its work at | ||
| # top level, so it cannot simply be sourced; the two values under test are lifted by pattern | ||
| # instead. That coupling is deliberate: if either declaration is renamed or reshaped, this test | ||
| # fails loudly rather than silently checking a stale copy of the filter. | ||
| extract_marker() { | ||
| sed -n 's/^MARKER="\(.*\)"$/\1/p' "$SCRIPT_DIR/agy-review.sh" | head -n 1 | ||
| } | ||
| extract_filter() { | ||
| sed -n "/^SELECT_STALE_JQ='/,/'\$/p" "$SCRIPT_DIR/agy-review.sh" \ | ||
| | sed "1s/^SELECT_STALE_JQ='//; \$s/'\$//" | ||
| } | ||
|
|
||
| MARKER="$(extract_marker)" | ||
| FILTER="$(extract_filter)" | ||
|
|
||
| [ -n "$MARKER" ] || { echo "FAIL: could not extract MARKER from agy-review.sh" >&2; exit 1; } | ||
| [ -n "$FILTER" ] || { echo "FAIL: could not extract SELECT_STALE_JQ from agy-review.sh" >&2; exit 1; } | ||
|
|
||
| # A non-empty extraction is not the same as a COMPLETE one. The `sed` range above ends at the | ||
| # first line closing with a quote, so a filter whose body ever ends a line that way would be | ||
| # truncated — and a truncated jq program can still be valid and still return ids, which is the | ||
| # silent-wrong-answer this whole file exists to prevent. Two independent guards: | ||
| # | ||
| # 1. it must compile (a truncated program is usually, though not always, a syntax error); | ||
| # 2. it must END with the projection, which is what makes it a complete pipeline rather than a | ||
| # prefix of one. | ||
| # The named args must be supplied here too: the filter references `$marker`/`$new_id`, and jq | ||
| # rejects an undefined variable at COMPILE time — so omitting them fails a perfectly good program. | ||
| if ! printf '[]' | jq --arg marker x --argjson new_id 0 "$FILTER" >/dev/null 2>&1; then | ||
| echo "FAIL: extracted SELECT_STALE_JQ is not a valid jq program (truncated?):" >&2 | ||
| printf '%s\n' "$FILTER" >&2 | ||
| exit 1 | ||
| fi | ||
| case "$(printf '%s' "$FILTER" | tr -d '[:space:]')" in | ||
| *'|.id') : ;; | ||
| *) echo "FAIL: extracted SELECT_STALE_JQ does not end in '| .id'; extraction truncated" >&2 | ||
| printf '%s\n' "$FILTER" >&2 | ||
| exit 1 ;; | ||
| esac | ||
|
|
||
| fixture() { | ||
| cat <<JSON | ||
| [ | ||
| {"id": 111, "user": {"type": "Bot", "login": "github-actions[bot]"}, "body": "$MARKER\nold review"}, | ||
| {"id": 222, "user": {"type": "Bot", "login": "github-actions[bot]"}, "body": "$MARKER\nolder still"}, | ||
| {"id": 333, "user": {"type": "User", "login": "someone"}, "body": "$MARKER\nnot ours"}, | ||
| {"id": 444, "user": {"type": "Bot", "login": "other-bot"}, "body": "$MARKER\nwrong bot"}, | ||
| {"id": 555, "user": {"type": "Bot", "login": "github-actions[bot]"}, "body": "an ordinary bot comment"}, | ||
| {"id": 999, "user": {"type": "Bot", "login": "github-actions[bot]"}, "body": "$MARKER\nJUST POSTED"} | ||
| ] | ||
| JSON | ||
| } | ||
|
|
||
| # Ids as a single space-separated line, with no trailing space — so the expected values below read | ||
| # as what they are rather than carrying padding an assertion would have to mirror. | ||
| select_ids() { | ||
| fixture | jq -r --arg marker "$MARKER" --argjson new_id "$1" "$FILTER" | sort -n | paste -sd' ' - | ||
| } | ||
|
|
||
| fails=0 | ||
| check() { | ||
| local name="$1" want="$2" got="$3" | ||
| if [ "$got" = "$want" ]; then | ||
| echo " ok $name" | ||
| else | ||
| echo " FAIL $name" | ||
| echo " want: [$want]" | ||
| echo " got: [$got]" | ||
| fails=$((fails + 1)) | ||
| fi | ||
| } | ||
|
|
||
| echo "agy-review comment-selection self-test" | ||
|
|
||
| # The whole point: the comment just published is never selected for deletion. | ||
| check "excludes the just-posted comment" "111 222" "$(select_ids 999)" | ||
|
|
||
| # The author filter is a security control, not tidiness: without it any user could paste the | ||
| # marker into a comment and have the bot delete comments on the next run. | ||
| check "ignores other users and other bots" "111 222" "$(select_ids 999)" | ||
|
|
||
| # A bot comment without the marker is somebody else's feature (a CI summary, a deploy note). | ||
| check "ignores bot comments without the marker" "111 222" "$(select_ids 999)" | ||
|
|
||
| # Regression #1, pinned: an unknown id must not select everything. The caller now refuses to run | ||
| # the delete at all in this case, but the filter itself is checked so the two guards are | ||
| # independent rather than one relying on the other. | ||
| check "an id of 0 still excludes nothing real" "111 222 999" "$(select_ids 0)" | ||
|
|
||
| # A different id in the set behaves the same way, so the exclusion is genuinely by value. | ||
| check "excludes whichever id it is given" "222 999" "$(select_ids 111)" | ||
|
|
||
| # Regression #2, pinned: `--arg`/`--argjson` belong to jq. If they are ever moved onto `gh api` | ||
| # again, that command exits non-zero — assert the flags are not passed to `gh api` in the script. | ||
| # Line continuations are folded first: `--arg` moved onto a continuation line would otherwise sit | ||
| # on a different physical line from `gh api`, and a line-by-line grep would report a false pass on | ||
| # exactly the mistake this check exists to catch. | ||
| if sed -e ':a' -e '/\\$/{N;s/\\\n//;ba' -e '}' "$SCRIPT_DIR/agy-review.sh" \ | ||
| | grep -qE 'gh api[^|]*--(arg|argjson)'; then | ||
| echo " FAIL --arg/--argjson passed to \`gh api\` (jq flags; gh api rejects them)" | ||
| fails=$((fails + 1)) | ||
| else | ||
| echo " ok --arg/--argjson are not passed to \`gh api\`" | ||
| fi | ||
|
|
||
| if [ "$fails" -ne 0 ]; then | ||
| echo "$fails check(s) failed" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "all checks passed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Does the gh CLIgh pr commentcommand print the created comment's URL to stdout on success, and is this documented/stable behavior?💡 Result:
The
gh pr commentcommand in the GitHub CLI does not print the created comment's URL to stdout upon success [1][2]. The command is designed for interaction with the GitHub PR system, and its standard behavior is to perform the requested action (posting the comment) without returning the URL or other machine-readable metadata about the created resource to standard output [1][2]. Because this behavior is not documented as a feature of the command, it is not considered a stable or supported way to retrieve the comment URL [1]. Users who need the URL or further details about the created comment should instead use thegh apicommand, which allows for direct interaction with the GitHub REST API and can return the full JSON response containing the resource URL [2][3]. For example, to obtain the comment URL or ID, you can use the REST API endpoint for creating a comment viagh api[2][4]: gh api --method POST /repos/{owner}/{repo}/issues/{issue_number}/comments -f body="your comment body" This approach provides a stable, machine-readable output that includes the full details of the created resource [2][3].Citations:
🏁 Script executed:
Repository: doublegate/RustyNES
Length of output: 6944
🌐 Web query:
site:cli.github.com/manual/gh_pr_comment gh pr comment output URL stdout💡 Result:
The gh pr comment command does not explicitly output the URL of the created comment to standard output (stdout) [1]. The official documentation for gh pr comment lists options for specifying the body of the comment, such as using --body or --body-file, but it does not document an option to return the URL of the resulting comment upon successful execution [1]. Because this information is not provided by the command's standard output, it is not possible to capture the comment URL directly from the command execution in the manner requested [1].
Citations:
🌐 Web query:
site:github.com/cli/cli "pr comment" "issuecomment-" output💡 Result:
The term "issuecomment-" refers to the prefix used in GitHub's REST and GraphQL APIs to identify individual comments on issues or pull requests [1][2]. In the context of GitHub Actions and the GitHub CLI (gh), this prefix is used when referencing specific comments for operations like updates or deletions [2][3]. Key points regarding "issuecomment-" and GitHub operations: 1. Identification: GitHub identifies comments using a unique numeric ID [1]. When interacting with the API or using tools that interface with it, these IDs are often prefixed with "issuecomment-" (e.g., issuecomment-123456789) to explicitly denote the object type [2]. 2. Usage in GitHub CLI: While the GitHub CLI (gh) provides high-level commands like gh pr comment --edit-last to simplify common tasks [4][2], it does not natively provide a direct command like gh comment update that takes an "issuecomment-" ID as a primary argument [1][2]. Instead, users often interact with these IDs via the GitHub API directly using gh api [2] or by piping JSON output from commands like gh issue view --json comments into tools like jq [1][3]. 3. PR vs. Issue Comments: In GitHub's data model, a pull request is a type of issue, meaning that comments on pull requests are technically issue comments [5][6]. This is why the same API endpoint (/repos/{owner}/{repo}/issues/comments/{comment_id}) is used to manage comments for both issues and pull requests [1]. 4. Automation and Permissions: When attempting to post or manage comments within a GitHub Actions workflow, ensure your job has the appropriate permissions (typically pull-requests: write or issues: write) [7][6]. If you encounter errors, verify that you are using the correct secret (secrets.GITHUB_TOKEN) and that the workflow event (e.g., pull_request vs. pull_request_target) provides the necessary access to the repository [6]. If you are trying to automate the updating or deletion of a comment, the recommended pattern is to retrieve the list of comments via the GitHub CLI in JSON format, use jq to filter for the specific comment ID, and then call the REST API via gh api [2][3].
Citations:
gh pr/issue commentallow editing selected comments cli/cli#10865gh pr commentdoes not work even withpermissions: write-allin workflow cli/cli#8374gh pr commentdoes not work even withpermissions: write-allin workflow cli/cli#8374🏁 Script executed:
Repository: doublegate/RustyNES
Length of output: 586
🌐 Web query:
GitHub CLI source pkg/cmd/pr/comment/comment.go prints comment URL Fprintln💡 Result:
In the GitHub CLI (gh) source code, the logic for adding a comment to a pull request is not entirely contained within
pkg/cmd/pr/comment/comment.go, which serves primarily as the command definition [1]. Instead, the operational logic—including the printing of the resulting comment URL—is largely delegated to shared functionality found inpkg/cmd/pr/shared/commentable.go[2]. Specifically, when a comment is successfully created via the GitHub API, thecommentable.gofile usesfmt.Fprintlnto output the URL of the new comment to the standard output stream (unless the quiet flag is set) [2]. The relevant code block typically looks like this: if!opts.Quiet { fmt.Fprintln(opts.IO.Out, url) } This behavior ensures that after executinggh pr comment, the user is provided with a direct link to the created resource [3][2]. Other formatting and printing of existing comments (e.g., when viewing them) are handled separately in files such aspkg/cmd/pr/shared/comments.go, which also utilizefmt.Fprintlnto format and display comment bodies and their associated metadata in the terminal [4].Citations:
🏁 Script executed:
Repository: doublegate/RustyNES
Length of output: 530
🌐 Web query:
site:cli.github.com/manual/gh_pr_comment "URL" "standard output"💡 Result:
There is no technical concept known as URL standard output. The phrase appears to be a misunderstanding or a conflation of terms. The WHATWG URL Standard defines how URLs are parsed and serialized [1], but it does not define an output format under that specific name. In command-line interface tools, such as the GitHub CLI, standard output is a common concept where commands return information to the terminal or allow data to be piped from a file [1].
Citations:
🌐 Web query:
site:cli.github.com/manual/gh_pr_comment "quiet" "comment"💡 Result:
No results were found for:
site:cli.github.com/manual/gh_pr_comment "quiet" "comment"The GitHub CLI manual page may not contain a
quietoption forgh pr comment.🏁 Script executed:
Repository: doublegate/RustyNES
Length of output: 8849
🏁 Script executed:
Repository: doublegate/RustyNES
Length of output: 23612
🌐 Web query:
GitHub CLI gh pr comment manual created comment URL printed stdout💡 Result:
The GitHub CLI
gh pr commentcommand does not natively print the URL of the created comment to standard output (stdout) [1][2]. The command primarily functions to add a comment and provides user feedback (if any) via standard error (stderr) or the terminal display when run interactively, rather than returning the new comment's URL as machine-readable output. If you need to obtain the URL of a newly created comment within a script, you can use thegh apicommand instead ofgh pr comment. By using the GitHub REST API, you can capture the JSON response, which contains thehtml_urlof the comment [3][4]. Example approach usinggh api: # Example script to create a comment and capture its URL comment_url=$(gh api \ --method POST \ -H "Accept: application/vnd.github+json" \ /repos/:owner/:repo/issues/:number/comments \ -f body="Your comment text here" \ --jq.html_url) echo "Comment created at: $comment_url" This method gives you direct access to the created comment's URL, which you can then store or process as needed [5].Citations:
Pin
ghor use a machine-readable comment responseThe current
gh pr commentimplementation prints the created URL when--quietis absent, and this invocation does not use--quiet. However, the manual does not document this stdout contract, and the workflow does not pin aghversion. Pin the CLI version and test the output, or create the comment withgh apiand parse its JSONid.🤖 Prompt for AI Agents