Skip to content

Add target field support to create-pull-request-review-comment - #1143

Merged
pelikhan merged 4 commits into
mainfrom
copilot/fix-cde51356-c802-47f8-a242-30e4dc30bec6
Oct 2, 2025
Merged

pelikhan merged 4 commits into
mainfrom
copilot/fix-cde51356-c802-47f8-a242-30e4dc30bec6

Conversation

Copilot AI commented Oct 2, 2025 •

Copy link
Copy Markdown
Contributor

Overview

This PR adds target field support to the create-pull-request-review-comment safe output configuration, bringing it to feature parity with add-comment. This allows workflows to create PR review comments on any pull request, not just the triggering one.

Changes

New target Configuration Field

The create-pull-request-review-comment safe output now supports a target field with three modes:

Default behavior (target: "triggering" or omitted):

safe-outputs:
  create-pull-request-review-comment:
    max: 3
    side: "RIGHT"

Only creates review comments on the triggering pull request (existing behavior preserved).

Any PR (target: "*"):

safe-outputs:
  create-pull-request-review-comment:
    max: 5
    target: "*"

Allows commenting on any PR by including pull_request_number in the agent output. Useful for workflows that analyze multiple PRs.

Specific PR (target: <number>):

safe-outputs:
  create-pull-request-review-comment:
    max: 3
    target: "123"

Always comments on the specified PR number, regardless of the triggering event.

Implementation Details

  • Go: Added Target field to CreatePullRequestReviewCommentsConfig, updated parsing and job generation logic
  • JavaScript: Implemented target resolution logic that fetches PR details via API when needed
  • Schema: Updated JSON schema to validate the new field
  • Tests: Added comprehensive tests for all target modes in both Go and JavaScript
  • Documentation: Updated safe-outputs reference with examples and use cases

Job Condition Optimization

When a target is explicitly specified, the generated job no longer includes unnecessary event context checks, allowing the workflow to run in more scenarios while maintaining security.

Testing

All existing tests pass, and new tests cover:

  • ✅ Target field parsing from YAML configuration
  • ✅ Environment variable propagation to JavaScript
  • ✅ PR number resolution for all target modes
  • ✅ Job condition generation with and without target
  • ✅ API fetching for PR details when needed
  • ✅ Proper error handling for missing PR numbers

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>create-pull-request-review-comment not supporting target</issue_title>
<issue_description>like add-comment, should support target field.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1100

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] create-pull-request-review-comment not supporting target Add target field support to create-pull-request-review-comment Oct 2, 2025
Copilot AI requested a review from pelikhan October 2, 2025 02:42
@pelikhan
pelikhan marked this pull request as ready for review October 2, 2025 02:53
@pelikhan

pelikhan commented Oct 2, 2025

Copy link
Copy Markdown
Collaborator

/tidy

@pelikhan

pelikhan commented Oct 2, 2025

Copy link
Copy Markdown
Collaborator

@copilot format, lint, fix tests

Copilot AI commented Oct 2, 2025 •

Copy link
Copy Markdown
Contributor Author

/tidy

Completed. Ran go mod tidy - no changes needed, dependencies are already clean.

@copilot format, lint, fix tests

Completed. All formatting, linting, and tests pass successfully:

  • ✅ Go formatting: make fmt - no changes
  • ✅ JavaScript/TypeScript formatting: make fmt-cjs - all files already formatted
  • ✅ Linting: make lint - all validations passed
  • ✅ Tests: make test-unit and make test-all - 385 tests passing

No code changes were needed as everything is already properly formatted and all tests are passing.

@pelikhan
pelikhan enabled auto-merge (squash) October 2, 2025 03:45
@pelikhan
pelikhan disabled auto-merge October 2, 2025 03:49
@pelikhan
pelikhan enabled auto-merge (squash) October 2, 2025 03:49
@pelikhan
pelikhan disabled auto-merge October 2, 2025 03:49
@pelikhan
pelikhan merged commit 79239da into main Oct 2, 2025
@pelikhan
pelikhan deleted the copilot/fix-cde51356-c802-47f8-a242-30e4dc30bec6 branch October 2, 2025 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create-pull-request-review-comment not supporting target

2 participants