Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 18, 2025

This PR adds a new GitHub Action workflow that allows maintainers to automatically format code in pull requests or branches using the project's pnpm format script.

🎯 Problem Solved

Previously, when contributors submitted PRs with formatting issues, maintainers had to either:

  • Ask contributors to fix formatting manually
  • Check out the branch locally, run formatting, and push changes
  • Accept PRs with inconsistent formatting

This workflow automates the formatting process, making it easy to ensure code consistency across all contributions.

🚀 New Feature: Format PR Workflow

The new workflow (.github/workflows/format-pr.yml) provides:

Manual Trigger Interface

  • Accessible via Actions → Format PR → Run workflow
  • Two input options:
    • Type: Choose between "branch" or "pull_request"
    • Reference: Enter branch name (e.g., feature/my-branch) or PR number (e.g., 123)

Smart Processing

  • Input validation: Ensures PR numbers are numeric and branch names are valid
  • Conditional execution: Only commits changes if formatting is actually needed
  • Proper attribution: Commits made by github-actions[bot] with detailed messages

Robust Error Handling

  • Validates inputs before processing
  • Provides clear error messages for invalid inputs
  • Includes comprehensive logging for troubleshooting

📋 Usage Examples

Format a specific PR:

  1. Select "pull_request"
  2. Enter PR number: 456
  3. Action formats the PR's head branch and commits changes

Format a branch:

  1. Select "branch"
  2. Enter branch name: fix-formatting-issues
  3. Action formats the branch and commits changes

🔧 Technical Details

The workflow:

  1. Validates user inputs (PR numbers must be numeric, branch names valid)
  2. Checks out the target branch/PR using appropriate Git references
  3. Sets up Node.js, pnpm, and installs dependencies
  4. Runs pnpm format:check to detect formatting issues
  5. If needed, runs pnpm format and commits changes with descriptive messages
  6. Pushes changes back to the original branch/PR

📚 Documentation

Includes comprehensive documentation at .github/workflows/FORMAT_PR.md explaining:

  • How to trigger the workflow
  • Input parameter details
  • Example usage scenarios
  • What the workflow does step-by-step

This enhancement streamlines the code review process and helps maintain consistent formatting standards across the entire codebase.


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

Copy link

changeset-bot bot commented Sep 18, 2025

⚠️ No Changeset found

Latest commit: a90b6d0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Copilot Copilot AI changed the title [WIP] Write a GitHub action that commit an extra change on a pr by running the pnpm format script. The script should be triggered by a manual trigger via actions where we select either the branch or the pr Add GitHub Action for automatically formatting code in PRs and branches Sep 18, 2025
@Copilot Copilot AI requested a review from dubzzz September 18, 2025 23:11
Copilot finished work on behalf of dubzzz September 18, 2025 23:11
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.

2 participants