From cf9b52c0c83f3d1e6605e51fc111a42236f9ef8c Mon Sep 17 00:00:00 2001 From: egg Date: Sun, 8 Feb 2026 05:28:19 +0000 Subject: [PATCH 1/2] Handle @mentions in PR review submissions The on-mention workflow only handled pull_request_review_comment events (inline code comments), not pull_request_review events (full review submissions). When a user submitted a review with @james-in-a-box in the body, the workflow never triggered. Add pull_request_review:submitted as a trigger event, with corresponding mention detection, acknowledgment, checkout ref, and prompt building logic. The prompt builder also fetches any inline comments attached to the review for full context. --- .github/workflows/on-mention.yml | 12 ++++- action/build-mention-prompt.sh | 80 +++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/.github/workflows/on-mention.yml b/.github/workflows/on-mention.yml index 86784d6adc..b0a82ca899 100644 --- a/.github/workflows/on-mention.yml +++ b/.github/workflows/on-mention.yml @@ -5,6 +5,8 @@ on: types: [created] pull_request_review_comment: types: [created] + pull_request_review: + types: [submitted] issues: types: [opened] @@ -18,6 +20,7 @@ jobs: ( (github.event_name == 'issue_comment' && (contains(github.event.comment.body, '@james-in-a-box') || contains(github.event.comment.body, '@egg'))) || (github.event_name == 'pull_request_review_comment' && (contains(github.event.comment.body, '@james-in-a-box') || contains(github.event.comment.body, '@egg'))) || + (github.event_name == 'pull_request_review' && (contains(github.event.review.body, '@james-in-a-box') || contains(github.event.review.body, '@egg'))) || (github.event_name == 'issues' && (contains(github.event.issue.body, '@james-in-a-box') || contains(github.event.issue.body, '@egg'))) ) && github.event.sender.login == 'jwbron' && @@ -58,6 +61,11 @@ jobs: gh api \ repos/${{ github.repository }}/pulls/comments/${{ github.event.comment.id }}/reactions \ -X POST -f content='eyes' + elif [[ "${{ github.event_name }}" == "pull_request_review" ]]; then + # No reaction API for reviews — acknowledge via PR comment + gh api \ + repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \ + -X POST -f body='👀 Working on it...' else # React to the issue/PR comment gh api \ @@ -81,7 +89,7 @@ jobs: echo "ref=main" >> "$GITHUB_OUTPUT" echo "is_pr=false" >> "$GITHUB_OUTPUT" fi - elif [[ "${{ github.event_name }}" == "pull_request_review_comment" ]]; then + elif [[ "${{ github.event_name }}" == "pull_request_review_comment" || "${{ github.event_name }}" == "pull_request_review" ]]; then echo "ref=${PR_HEAD_REF}" >> "$GITHUB_OUTPUT" echo "is_pr=true" >> "$GITHUB_OUTPUT" else @@ -143,7 +151,7 @@ jobs: fi # Determine where to post the comment - if [[ "${{ github.event_name }}" == "pull_request_review_comment" ]]; then + if [[ "${{ github.event_name }}" == "pull_request_review_comment" || "${{ github.event_name }}" == "pull_request_review" ]]; then ISSUE_NUMBER="${{ github.event.pull_request.number }}" else ISSUE_NUMBER="${{ github.event.issue.number }}" diff --git a/action/build-mention-prompt.sh b/action/build-mention-prompt.sh index ffcfa903aa..a62f2ffd00 100755 --- a/action/build-mention-prompt.sh +++ b/action/build-mention-prompt.sh @@ -5,7 +5,7 @@ # additional context, then outputs a structured prompt via $GITHUB_OUTPUT. # # Environment variables: -# GITHUB_EVENT_NAME — event type (issue_comment, pull_request_review_comment, issues) +# GITHUB_EVENT_NAME — event type (issue_comment, pull_request_review_comment, pull_request_review, issues) # GITHUB_EVENT_PATH — path to event JSON payload # GITHUB_REPOSITORY — owner/repo # BOT_USERNAME — bot name to strip from mention (default: james-in-a-box) @@ -250,6 +250,84 @@ branch (${pr_head}). Make the requested changes, commit, and push. Then reply to review comment confirming what you changed." ;; + pull_request_review) + local pr_number + local pr_title + local pr_url + local pr_head + local pr_base + local review_body + local review_state + + pr_number=$(jq_raw '.pull_request.number') + pr_title=$(jq_raw '.pull_request.title') + pr_url=$(jq_raw '.pull_request.html_url') + pr_head=$(jq_raw '.pull_request.head.ref') + pr_base=$(jq_raw '.pull_request.base.ref') + review_body=$(jq_raw '.review.body') + review_state=$(jq_raw '.review.state') + + local pr_details + pr_details=$(fetch_pr_details "$pr_number") + local pr_body_raw pr_body pr_state pr_merged pr_display_state + pr_state=$(echo "$pr_details" | jq -r '.state') + pr_merged=$(echo "$pr_details" | jq -r '.merged') + pr_body_raw=$(echo "$pr_details" | jq -r '.body // ""') + pr_body=$(truncate_text "$pr_body_raw" "$MAX_BODY_CHARS") + pr_display_state="$pr_state" + if [[ "$pr_merged" == "true" ]]; then + pr_display_state="merged" + fi + + local changed_files + changed_files=$(fetch_pr_files "$pr_number") + + local recent_comments + recent_comments=$(fetch_recent_comments "$pr_number") + + # Fetch review comments (inline comments attached to this review) + local review_comments="" + local review_id + review_id=$(jq_raw '.review.id') + review_comments=$(gh_api_safe "repos/${GITHUB_REPOSITORY}/pulls/${pr_number}/reviews/${review_id}/comments" \ + --jq '.[] | "### \(.path):\(.line // .original_line // "?")\n\(.diff_hunk)\n\n\(.body)\n"' 2>/dev/null || true) + + prompt="You were mentioned in a pull request review submission. + +Repository: ${GITHUB_REPOSITORY} +Pull Request: #${pr_number} — ${pr_title} +PR URL: ${pr_url} +PR state: ${pr_display_state} +PR base: ${pr_base} <- ${pr_head} +Review state: ${review_state} + +## PR description +${pr_body} + +## Changed files +${changed_files} + +## Recent conversation (last 10 comments) +${recent_comments} + +## Review body +${review_body} +" + + if [[ -n "$review_comments" ]]; then + prompt+=" +## Inline review comments +${review_comments} +" + fi + + prompt+=" +## Your task +Address the review feedback above. You are checked out on the PR's head +branch (${pr_head}). Make the requested changes, commit, and push. Then reply +to the review confirming what you changed." + ;; + issues) local issue_number local issue_title From 1b161217ac4424c48f1c3a8b9bd88f6d5d9a0db2 Mon Sep 17 00:00:00 2001 From: jwbron <8340608+jwbron@users.noreply.github.com> Date: Sun, 8 Feb 2026 05:56:47 +0000 Subject: [PATCH 2/2] Address review feedback for review body handling - Add null fallback for review_body extraction to handle reviews submitted with only inline comments (no summary body) - Truncate diff_hunk in review comments to prevent excessively large prompts from reviews with many inline comments - Add defensive null check in workflow condition for review.body - Remove redundant stderr redirect (gh_api_safe handles it) Authored-by: egg --- .github/workflows/on-mention.yml | 2 +- action/build-mention-prompt.sh | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/on-mention.yml b/.github/workflows/on-mention.yml index b0a82ca899..7fb7354e1f 100644 --- a/.github/workflows/on-mention.yml +++ b/.github/workflows/on-mention.yml @@ -20,7 +20,7 @@ jobs: ( (github.event_name == 'issue_comment' && (contains(github.event.comment.body, '@james-in-a-box') || contains(github.event.comment.body, '@egg'))) || (github.event_name == 'pull_request_review_comment' && (contains(github.event.comment.body, '@james-in-a-box') || contains(github.event.comment.body, '@egg'))) || - (github.event_name == 'pull_request_review' && (contains(github.event.review.body, '@james-in-a-box') || contains(github.event.review.body, '@egg'))) || + (github.event_name == 'pull_request_review' && github.event.review.body != null && (contains(github.event.review.body, '@james-in-a-box') || contains(github.event.review.body, '@egg'))) || (github.event_name == 'issues' && (contains(github.event.issue.body, '@james-in-a-box') || contains(github.event.issue.body, '@egg'))) ) && github.event.sender.login == 'jwbron' && diff --git a/action/build-mention-prompt.sh b/action/build-mention-prompt.sh index a62f2ffd00..14f2ea7088 100755 --- a/action/build-mention-prompt.sh +++ b/action/build-mention-prompt.sh @@ -264,7 +264,7 @@ review comment confirming what you changed." pr_url=$(jq_raw '.pull_request.html_url') pr_head=$(jq_raw '.pull_request.head.ref') pr_base=$(jq_raw '.pull_request.base.ref') - review_body=$(jq_raw '.review.body') + review_body=$(jq_raw '.review.body // ""') review_state=$(jq_raw '.review.state') local pr_details @@ -289,8 +289,23 @@ review comment confirming what you changed." local review_comments="" local review_id review_id=$(jq_raw '.review.id') - review_comments=$(gh_api_safe "repos/${GITHUB_REPOSITORY}/pulls/${pr_number}/reviews/${review_id}/comments" \ - --jq '.[] | "### \(.path):\(.line // .original_line // "?")\n\(.diff_hunk)\n\n\(.body)\n"' 2>/dev/null || true) + local review_comments_json + review_comments_json=$(gh_api_safe "repos/${GITHUB_REPOSITORY}/pulls/${pr_number}/reviews/${review_id}/comments") + if [[ -n "$review_comments_json" && "$review_comments_json" != "[]" ]]; then + review_comments=$(echo "$review_comments_json" | jq -r '.[] | @base64' | while read -r encoded; do + local path line diff_hunk body + path=$(echo "$encoded" | base64 -d | jq -r '.path // ""') + line=$(echo "$encoded" | base64 -d | jq -r '.line // .original_line // "?"') + diff_hunk=$(echo "$encoded" | base64 -d | jq -r '.diff_hunk // ""') + body=$(echo "$encoded" | base64 -d | jq -r '.body // ""') + diff_hunk=$(truncate_text "$diff_hunk" "$MAX_BODY_CHARS") + echo "### ${path}:${line}" + echo "$diff_hunk" + echo "" + echo "$body" + echo "" + done) + fi prompt="You were mentioned in a pull request review submission.