@@ -27,29 +27,104 @@ jobs:
2727 (github.event_name == 'issues' && (contains(github.event.issue.body, '@agentready-dev') || contains(github.event.issue.title, '@agentready-dev')))
2828 runs-on : ubuntu-latest
2929 steps :
30+ - name : Determine event context
31+ id : event-context
32+ run : |
33+ EVENT_NAME="${{ github.event_name }}"
34+
35+ # Determine if this is a PR-related event and get the PR number
36+ {
37+ if [ "$EVENT_NAME" == "pull_request_review_comment" ]; then
38+ # pull_request_review_comment events have github.event.pull_request
39+ PR_NUMBER="${{ github.event.pull_request.number }}"
40+ echo "is_pr=true"
41+ echo "pr_number=$PR_NUMBER"
42+ echo "issue_number=$PR_NUMBER"
43+ elif [ "$EVENT_NAME" == "pull_request_review" ]; then
44+ # pull_request_review events have github.event.pull_request
45+ PR_NUMBER="${{ github.event.pull_request.number }}"
46+ echo "is_pr=true"
47+ echo "pr_number=$PR_NUMBER"
48+ echo "issue_number=$PR_NUMBER"
49+ elif [ "$EVENT_NAME" == "issue_comment" ]; then
50+ # issue_comment events have github.event.issue
51+ ISSUE_NUMBER="${{ github.event.issue.number }}"
52+ # Check if this issue is actually a PR by checking if pull_request.url exists
53+ # GitHub Actions will return empty string if pull_request doesn't exist
54+ PULL_REQUEST_URL="${{ github.event.issue.pull_request.url || '' }}"
55+ if [ -n "$PULL_REQUEST_URL" ] && [ "$PULL_REQUEST_URL" != "null" ] && [ "$PULL_REQUEST_URL" != "undefined" ]; then
56+ echo "is_pr=true"
57+ echo "pr_number=$ISSUE_NUMBER"
58+ else
59+ echo "is_pr=false"
60+ fi
61+ echo "issue_number=$ISSUE_NUMBER"
62+ elif [ "$EVENT_NAME" == "issues" ]; then
63+ # issues events have github.event.issue
64+ ISSUE_NUMBER="${{ github.event.issue.number }}"
65+ # Check if this issue is actually a PR by checking if pull_request.url exists
66+ # GitHub Actions will return empty string if pull_request doesn't exist
67+ PULL_REQUEST_URL="${{ github.event.issue.pull_request.url || '' }}"
68+ if [ -n "$PULL_REQUEST_URL" ] && [ "$PULL_REQUEST_URL" != "null" ] && [ "$PULL_REQUEST_URL" != "undefined" ]; then
69+ echo "is_pr=true"
70+ echo "pr_number=$ISSUE_NUMBER"
71+ else
72+ echo "is_pr=false"
73+ fi
74+ echo "issue_number=$ISSUE_NUMBER"
75+ else
76+ echo "is_pr=false"
77+ echo "issue_number="
78+ fi
79+ } >> "$GITHUB_OUTPUT"
80+
3081 - name : Get PR info for fork support
31- if : github .event.issue.pull_request
82+ if : steps .event-context.outputs.is_pr == 'true'
3283 id : pr-info
3384 env :
3485 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3586 REPOSITORY : ${{ github.repository }}
36- ISSUE_NUMBER : ${{ github.event.issue.number }}
87+ PR_NUMBER : ${{ steps.event-context.outputs.pr_number }}
88+ EVENT_NAME : ${{ github.event_name }}
89+ PR_HEAD_SHA_INPUT : ${{ github.event.pull_request.head.sha }}
90+ PR_HEAD_REF_INPUT : ${{ github.event.pull_request.head.ref }}
91+ PR_HEAD_OWNER_INPUT : ${{ github.event.pull_request.head.repo.owner.login }}
92+ PR_HEAD_REPO_INPUT : ${{ github.event.pull_request.head.repo.name }}
93+ PR_HEAD_FORK_INPUT : ${{ github.event.pull_request.head.repo.fork }}
3794 run : |
38- PR_DATA=$(gh api "repos/$REPOSITORY/pulls/$ISSUE_NUMBER")
95+ # For pull_request_review_comment and pull_request_review events, we have direct access
96+ if [ "$EVENT_NAME" == "pull_request_review_comment" ] || [ "$EVENT_NAME" == "pull_request_review" ]; then
97+ PR_HEAD_SHA="$PR_HEAD_SHA_INPUT"
98+ PR_HEAD_REF="$PR_HEAD_REF_INPUT"
99+ PR_HEAD_OWNER="$PR_HEAD_OWNER_INPUT"
100+ PR_HEAD_REPO="$PR_HEAD_REPO_INPUT"
101+ IS_FORK="$PR_HEAD_FORK_INPUT"
102+ else
103+ # For issue_comment and issues events on PRs, fetch from API
104+ PR_DATA=$(gh api "repos/$REPOSITORY/pulls/$PR_NUMBER")
105+ PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r '.head.sha')
106+ PR_HEAD_REF=$(echo "$PR_DATA" | jq -r '.head.ref')
107+ PR_HEAD_OWNER=$(echo "$PR_DATA" | jq -r '.head.repo.owner.login')
108+ PR_HEAD_REPO=$(echo "$PR_DATA" | jq -r '.head.repo.name')
109+ IS_FORK=$(echo "$PR_DATA" | jq -r '.head.repo.fork')
110+ fi
111+
39112 {
40- echo "pr_head_owner=$(echo "$PR_DATA" | jq -r '.head.repo.owner.login')"
41- echo "pr_head_repo=$(echo "$PR_DATA" | jq -r '.head.repo.name')"
42- echo "pr_head_ref=$(echo "$PR_DATA" | jq -r '.head.ref')"
43- echo "is_fork=$(echo "$PR_DATA" | jq -r '.head.repo.fork')"
113+ echo "pr_head_owner=$PR_HEAD_OWNER"
114+ echo "pr_head_repo=$PR_HEAD_REPO"
115+ echo "pr_head_ref=$PR_HEAD_REF"
116+ echo "pr_head_sha=$PR_HEAD_SHA"
117+ echo "is_fork=$IS_FORK"
44118 } >> "$GITHUB_OUTPUT"
45119
46120 - name : Extract user request
47121 id : extract-request
48122 env :
49123 EVENT_NAME : ${{ github.event_name }}
50- COMMENT_BODY : ${{ github.event.comment.body }}
51- REVIEW_BODY : ${{ github.event.review.body }}
52- ISSUE_BODY : ${{ github.event.issue.body }}
124+ COMMENT_BODY : ${{ github.event.comment.body || '' }}
125+ REVIEW_BODY : ${{ github.event.review.body || '' }}
126+ ISSUE_BODY : ${{ github.event.issue.body || '' }}
127+ ISSUE_TITLE : ${{ github.event.issue.title || '' }}
53128 run : |
54129 case "$EVENT_NAME" in
55130 issue_comment|pull_request_review_comment)
@@ -59,7 +134,12 @@ jobs:
59134 REQUEST="$REVIEW_BODY"
60135 ;;
61136 issues)
62- REQUEST="$ISSUE_BODY"
137+ # Use body if available, otherwise use title
138+ if [ -n "$ISSUE_BODY" ]; then
139+ REQUEST="$ISSUE_BODY"
140+ else
141+ REQUEST="$ISSUE_TITLE"
142+ fi
63143 ;;
64144 *)
65145 REQUEST="No request body found"
@@ -75,11 +155,34 @@ jobs:
75155 echo "EOF"
76156 } >> "$GITHUB_OUTPUT"
77157
158+ - name : Determine checkout ref
159+ id : checkout-ref
160+ run : |
161+ if [ "${{ steps.event-context.outputs.is_pr }}" == "true" ]; then
162+ if [ "${{ steps.pr-info.outputs.is_fork }}" == "true" ]; then
163+ # Fork: checkout the fork repository at the PR branch
164+ echo "repository=${{ steps.pr-info.outputs.pr_head_owner }}/${{ steps.pr-info.outputs.pr_head_repo }}" >> "$GITHUB_OUTPUT"
165+ echo "ref=${{ steps.pr-info.outputs.pr_head_ref }}" >> "$GITHUB_OUTPUT"
166+ else
167+ # Same repo PR: checkout at PR head SHA
168+ echo "repository=${{ github.repository }}" >> "$GITHUB_OUTPUT"
169+ echo "ref=${{ steps.pr-info.outputs.pr_head_sha }}" >> "$GITHUB_OUTPUT"
170+ fi
171+ else
172+ # Regular issue: checkout default branch (checkout action will use default if ref is empty)
173+ echo "repository=${{ github.repository }}" >> "$GITHUB_OUTPUT"
174+ # github.ref may not be set for issue events, so leave ref empty to use default branch
175+ if [ -n "${{ github.ref }}" ] && [ "${{ github.ref }}" != "null" ]; then
176+ echo "ref=${{ github.ref }}" >> "$GITHUB_OUTPUT"
177+ fi
178+ # If ref is empty, checkout action will use repository's default branch
179+ fi
180+
78181 - name : Checkout repository (fork-compatible)
79182 uses : actions/checkout@v6
80183 with :
81- repository : ${{ github.event.issue.pull_request && steps.pr-info .outputs.is_fork == 'true' && format('{0}/{1}', steps.pr-info.outputs.pr_head_owner, steps.pr-info.outputs.pr_head_repo) || github .repository }}
82- ref : ${{ github.event.issue.pull_request && steps.pr-info .outputs.pr_head_ref || github.ref }}
184+ repository : ${{ steps.checkout-ref .outputs.repository }}
185+ ref : ${{ steps.checkout-ref .outputs.ref || '' }}
83186 fetch-depth : 0
84187
85188 - name : Claude Code Action
0 commit comments