Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/on-mention.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
types: [created]
pull_request_review_comment:
types: [created]
pull_request_review:
types: [submitted]
issues:
types: [opened]

Expand All @@ -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' && 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' &&
Expand Down Expand Up @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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 }}"
Expand Down
95 changes: 94 additions & 1 deletion action/build-mention-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -250,6 +250,99 @@ 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')
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.

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
Expand Down
Loading