Skip to content

Add reviewers field to create-pull-request safe output - #1981

Merged
pelikhan merged 8 commits into
mainfrom
copilot/add-reviewers-field-to-pr
Oct 19, 2025
Merged

pelikhan merged 8 commits into
mainfrom
copilot/add-reviewers-field-to-pr

Conversation

Copilot AI commented Oct 19, 2025 •

Copy link
Copy Markdown
Contributor

Add reviewers field to create-pull-request safe output ✅

This PR adds support for automatically assigning reviewers to pull requests created by the create-pull-request safe output, following the exact pattern used for assignees in create-issue.

Summary of Changes

1. Code Implementation

  • Added Reviewers field to CreatePullRequestsConfig struct
  • Updated parsing logic to support both string and array formats for reviewers
  • Added reviewer assignment steps that execute after PR creation:
    • Conditional checkout step for gh CLI (only when reviewers configured)
    • Individual reviewer steps using gh pr edit --add-reviewer
    • Proper GitHub token handling with precedence
    • Special mapping: copilot → internal Copilot bot username
    • Uses pr_url step output for gh CLI commands

2. Schema Updates

  • Updated main_workflow_schema.json to include reviewers field with proper validation
  • Supports both single string and array of strings
  • Includes descriptive help text for the "copilot" special value

3. Comprehensive Testing

  • 7 new unit tests covering:
    • Multiple reviewers
    • Single reviewer (string format)
    • No reviewers
    • Copilot mapping
    • Custom GitHub tokens
    • Parsing logic
  • 3 new integration tests for end-to-end compilation
  • 2 new test workflows demonstrating the feature:
    • test-claude-create-pull-request-reviewers.md (array format with multiple reviewers)
    • test-copilot-create-pull-request-reviewers.md (string format with single reviewer)
  • All existing tests continue to pass

4. Production Workflows Updated

  • Added reviewers: copilot to 9 agentic workflows that use create-pull-request:
    • daily-doc-updater.md
    • github-mcp-tools-report.md
    • poem-bot.md
    • q.md
    • security-fix-pr.md
    • technical-doc-writer.md
    • tidy.md
    • unbloat-docs.md

5. Documentation

  • Updated safe-outputs.md with:
    • Reviewers field in configuration examples
    • Detailed configuration options section
    • Section on "Assigning Issues and Pull Requests to Copilot"
    • Authentication requirements for bot reviewers
    • Comprehensive examples with PAT configuration
    • Note: Documentation focuses on user-facing features without exposing internal implementation details

Usage Example

---
on:
  pull_request:
    types: [opened]
permissions:
  contents: read
  actions: read
engine: copilot
safe-outputs:
  github-token: ${{ secrets.COPILOT_PAT }}  # Required for bot reviewers
  create-pull-request:
    reviewers: [copilot, user1, user2]
    labels: [automation, needs-review]
---

# PR Review Bot

Create follow-up PRs with automated reviewers assigned.

Verification

✅ All unit tests pass (7 new tests)
✅ All integration tests pass (3 new tests)
✅ Linting passes (Go, JavaScript, YAML)
✅ Schema validation passes
✅ Manual compilation verified
✅ Recompiled all workflows successfully (66 workflows)
✅ Documentation updated per feedback
✅ Test workflows created
✅ Production workflows updated with copilot reviewer

Files Changed

  • pkg/workflow/create_pull_request.go - Core implementation
  • pkg/workflow/create_pull_request_reviewers_test.go - Unit tests
  • pkg/workflow/create_pull_request_reviewers_integration_test.go - Integration tests
  • pkg/parser/schemas/main_workflow_schema.json - Schema updates
  • docs/src/content/docs/reference/safe-outputs.md - Documentation
  • 9 production workflows in .github/workflows/ - Added copilot as reviewer
  • 2 test workflows in pkg/cli/workflows/ - Demonstrating the feature

Ready for review! 🚀

Original prompt

Add an optimal field "reviewers" to the create-pull-request safe output that allows to assign reviewers to the created PRs.

  • accepts a single string or an array of user names
  • uses "gh pr edit --add-reviewer " in the safe output job to assign
  • if present, update the safe output job to add a checkout step to configure gh
  • use step output for the pr_url
  • if the assigned is copilot, update for the correct copilot reviewer user name
  • update docs and add section on "assigning issue to copilot

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

Copilot AI and others added 3 commits October 19, 2025 16:51
- Added Reviewers field to CreatePullRequestsConfig struct
- Updated parsePullRequestsConfig to parse reviewers (supports string or array)
- Added reviewer assignment steps in buildCreateOutputPullRequestJob
- Checkout step added when reviewers are configured
- Using gh pr edit --add-reviewer for each reviewer
- Maps "copilot" to "copilot-swe-agent"
- Uses pr_url step output for gh pr edit command
- Updated JSON schema to include reviewers field
- Added comprehensive unit tests for reviewers functionality
- Added integration tests for end-to-end compilation

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Added reviewers field to create-pull-request configuration examples
- Added configuration options section explaining reviewers functionality
- Added dedicated section on "Assigning Issues and Pull Requests to Copilot"
- Documented special "copilot" value mapping to copilot-swe-agent
- Documented authentication requirements for bot reviewers
- Added comprehensive examples with PAT configuration

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- All unit tests pass (7 new tests for reviewers)
- All integration tests pass (3 new tests)
- Linting passes (Go, JavaScript, YAML)
- Schema validation passes
- Manual compilation verified with multiple examples
- agent-finish completes successfully (64 workflows compiled)

Implementation complete and ready for review.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Comment thread docs/src/content/docs/reference/safe-outputs.md
Copilot AI changed the title [WIP] Add reviewers field for creating pull requests Add reviewers field to create-pull-request safe output Oct 19, 2025
Copilot AI requested a review from pelikhan October 19, 2025 17:01
- Removed all mentions of "copilot-swe-agent" from safe-outputs.md
- Updated to refer to "the Copilot bot" or "Copilot" instead
- Simplified "How It Works" section to avoid exposing internal implementation
- Updated code comments to use "the Copilot bot" phrasing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review October 19, 2025 17:13
@github-actions

Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

Comment on lines +967 to +980
### How It Works

When you use `copilot` in the `assignees` or `reviewers` configuration:

1. **Automatic Mapping**: The workflow automatically handles the special `copilot` value
2. **Step Name**: The generated workflow step shows "copilot" (e.g., "Assign issue to copilot" or "Add copilot as reviewer")
3. **Conditional Execution**: Assignment/reviewer steps only run if the issue or pull request was successfully created

### Benefits

- **Automated Review**: Copilot can automatically review pull requests and provide feedback
- **Issue Analysis**: Copilot can analyze and provide suggestions on assigned issues
- **Simple Configuration**: Use the friendly `copilot` value for easy setup
- **Safe Failure**: If assignment fails, the workflow continues (the issue/PR is still created)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove section

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the "How It Works" and "Benefits" sections. Changes in commit a0c8267.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds reviewer assignment capability to the create-pull-request safe output, mirroring assignee handling for issues.

  • Introduces Reviewers field in CreatePullRequestsConfig and parsing logic for string/array formats
  • Generates conditional gh CLI steps to add reviewers (supports copilot mapping and token precedence)
  • Updates schema and documentation plus adds unit/integration tests

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/workflow/create_pull_request.go Implements reviewers field, step generation, and config parsing
pkg/workflow/create_pull_request_reviewers_test.go Adds unit tests for reviewer parsing and step generation including token precedence
pkg/workflow/create_pull_request_reviewers_integration_test.go Verifies end-to-end compilation with various reviewer configurations
pkg/parser/schemas/main_workflow_schema.json Extends schema to accept reviewers as string or array
docs/src/content/docs/reference/safe-outputs.md Documents new reviewers option and Copilot assignment behavior
.github/workflows/dev.lock.yml Minor permissions ordering change (non-functional)
.changeset/patch-add-reviewers-field.md Records patch changeset metadata

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

steps = append(steps, " run: |\n")
steps = append(steps, " gh pr edit \"$PR_URL\" --add-reviewer \"$REVIEWER\"\n")

// Add a comment after each reviewer step except the last

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment claims to add a comment, but the code only inserts a blank newline for formatting. Recommend updating the comment to something like: // Insert a blank line between reviewer steps for readability, or remove the conditional + blank line if not required for YAML clarity.

Suggested change
// Add a comment after each reviewer step except the last
// Insert a blank line between reviewer steps for readability

Copilot uses AI. Check for mistakes.
**Configuration Options:**
- **`assignees:`** - GitHub username(s) to automatically assign to created issues. Accepts either a single string (`assignees: user1`) or an array of strings (`assignees: [user1, user2]`). The workflow automatically adds steps that call `gh issue edit --add-assignee` for each assignee after the issue is created. Only runs if the issue was successfully created.
- **Special value**: Use `copilot` to assign to the `copilot-swe-agent` bot
- **Special value**: Use `copilot` to assign to the Copilot bot

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This line omits the actual GitHub username mapping used in implementation (copilot-swe-agent). For clarity and consistency with the schema descriptions, update to: Use copilot to assign to the copilot-swe-agent bot (the Copilot reviewer account).

Suggested change
- **Special value**: Use `copilot` to assign to the Copilot bot
- **Special value**: Use `copilot` to assign to the `copilot-swe-agent` bot (the Copilot reviewer account)

Copilot uses AI. Check for mistakes.

**Configuration Options:**
- **`reviewers:`** - GitHub username(s) to automatically assign as reviewers to the created pull request. Accepts either a single string (`reviewers: user1`) or an array of strings (`reviewers: [user1, user2]`). The workflow automatically adds steps that call `gh pr edit --add-reviewer` for each reviewer after the pull request is created. Only runs if the pull request was successfully created.
- **Special value**: Use `copilot` to assign the Copilot bot as a reviewer

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The special value description does not state the actual mapped account (copilot-swe-agent), which may confuse users auditing permissions. Suggest revising line 258 to: Use copilot to assign the copilot-swe-agent bot (Copilot reviewer account).

Suggested change
- **Special value**: Use `copilot` to assign the Copilot bot as a reviewer
- **Special value**: Use `copilot` to assign the `copilot-swe-agent` bot (Copilot reviewer account) as a reviewer

Copilot uses AI. Check for mistakes.
## Assigning Issues and Pull Requests to Copilot

Both `create-issue` and `create-pull-request` safe outputs support assigning the created issue or adding reviewers to the pull request using the special value `copilot`. This provides automated code review and issue analysis.

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This section introduces the copilot special value but does not reiterate the concrete GitHub username (copilot-swe-agent). Adding that mapping here improves discoverability and reduces ambiguity for users verifying organization access controls.

Suggested change
> **Note:** The special value `copilot` refers to the GitHub user [`copilot-swe-agent`](https://github.com/copilot-swe-agent). Use this mapping to verify organization access controls.

Copilot uses AI. Check for mistakes.
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot

  • add copilot as reviewer to all agentic workflows (ignore test agentic workflow) that use create-pull-request safe output.

  • add test agentic workflow that uses reviewers field

- Removed detailed implementation explanation section
- Removed benefits section per feedback
- Kept essential usage examples and authentication requirements

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Added reviewers: copilot to 9 agentic workflows using create-pull-request:
  - daily-doc-updater.md
  - github-mcp-tools-report.md
  - poem-bot.md
  - q.md
  - security-fix-pr.md
  - technical-doc-writer.md
  - tidy.md
  - unbloat-docs.md

- Created test workflows demonstrating reviewers field:
  - test-claude-create-pull-request-reviewers.md (array format)
  - test-copilot-create-pull-request-reviewers.md (string format)

- Recompiled all workflows to generate updated .lock.yml files
- All tests pass

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Oct 19, 2025

Copy link
Copy Markdown
Contributor Author

@copilot

  • add copilot as reviewer to all agentic workflows (ignore test agentic workflow) that use create-pull-request safe output....

Added reviewers: copilot to all 9 agentic workflows using create-pull-request (excluding test workflows). Created two test workflows demonstrating the feature:

  • test-claude-create-pull-request-reviewers.md (array format with multiple reviewers)
  • test-copilot-create-pull-request-reviewers.md (string format with single reviewer)

All workflows compiled successfully. Changes in commit 1c8f5e1.

@pelikhan
pelikhan merged commit 2f47fb1 into main Oct 19, 2025
4 checks passed
@pelikhan
pelikhan deleted the copilot/add-reviewers-field-to-pr branch October 19, 2025 18:40
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.

3 participants