From 27427527b27d126af91467adb95c7b9ef15e770e Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 11 Sep 2025 19:30:56 +0100 Subject: [PATCH 1/2] fix code review comments part 2 --- pkg/workflow/compiler.go | 4 ++-- pkg/workflow/output_pr_review_comment_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/workflow/compiler.go b/pkg/workflow/compiler.go index 16a46b6ff48..a81e9a8bc98 100644 --- a/pkg/workflow/compiler.go +++ b/pkg/workflow/compiler.go @@ -2369,8 +2369,8 @@ func (c *Compiler) buildCreateOutputPullRequestReviewCommentJob(data *WorkflowDa "review_comment_url": "${{ steps.create_pr_review_comment.outputs.review_comment_url }}", } - // Only run in pull request context - baseCondition := "github.event.pull_request.number" + // We only run in pull request context, Note that in pull request comments only github.event.issue.pull_request is set. + baseCondition := "(github.event.issue.pull_request || github.event.pull_request)" // If this is a command workflow, combine the command trigger condition with the base condition var jobCondition string diff --git a/pkg/workflow/output_pr_review_comment_test.go b/pkg/workflow/output_pr_review_comment_test.go index 62e0d57e8a9..0ce19b5a5a8 100644 --- a/pkg/workflow/output_pr_review_comment_test.go +++ b/pkg/workflow/output_pr_review_comment_test.go @@ -243,7 +243,7 @@ This workflow tests job generation for PR review comments. } // Verify job condition is correct for PR context - if !strings.Contains(workflowContent, "if: github.event.pull_request.number") { + if !strings.Contains(workflowContent, "if: (github.event.issue.pull_request || github.event.pull_request)") { t.Error("Expected job condition to check for pull request context") } From c745e15c520c2c28479f48726e70e9566f2f27a3 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Thu, 11 Sep 2025 19:38:20 +0100 Subject: [PATCH 2/2] fix code review comment creation --- pkg/workflow/js/create_pr_review_comment.cjs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/workflow/js/create_pr_review_comment.cjs b/pkg/workflow/js/create_pr_review_comment.cjs index 727a6a87561..839ffdff515 100644 --- a/pkg/workflow/js/create_pr_review_comment.cjs +++ b/pkg/workflow/js/create_pr_review_comment.cjs @@ -78,11 +78,14 @@ async function main() { const defaultSide = process.env.GITHUB_AW_PR_REVIEW_COMMENT_SIDE || "RIGHT"; console.log(`Default comment side configuration: ${defaultSide}`); - // Check if we're in a pull request context + // Check if we're in a pull request context, or an issue comment context on a PR const isPRContext = context.eventName === "pull_request" || context.eventName === "pull_request_review" || - context.eventName === "pull_request_review_comment"; + context.eventName === "pull_request_review_comment" || + (context.eventName === "issue_comment" && + context.payload.issue && + context.payload.issue.pull_request); if (!isPRContext) { console.log( @@ -90,8 +93,9 @@ async function main() { ); return; } + const pullRequest = context.payload.pull_request || context.payload.issue.pull_request; - if (!context.payload.pull_request) { + if (!pullRequest) { console.log( "Pull request context detected but no pull request found in payload" ); @@ -100,8 +104,8 @@ async function main() { // Check if we have the commit SHA needed for creating review comments if ( - !context.payload.pull_request.head || - !context.payload.pull_request.head.sha + !pullRequest.head || + !pullRequest.head.sha ) { console.log( "Pull request head commit SHA not found in payload - cannot create review comments" @@ -109,7 +113,7 @@ async function main() { return; } - const pullRequestNumber = context.payload.pull_request.number; + const pullRequestNumber = pullRequest.number; console.log(`Creating review comments on PR #${pullRequestNumber}`); const createdComments = []; @@ -199,7 +203,7 @@ async function main() { pull_number: pullRequestNumber, body: body, path: commentItem.path, - commit_id: context.payload.pull_request.head.sha, // Required for creating review comments + commit_id: pullRequest.head.sha, // Required for creating review comments line: line, side: side, };