发布

  • feat(core): add GitHub repository creation and push functionality (#31936)

    frostbyte_neo 发布于 2025-07-18 03:41:36 +00:00

    Current Behavior

    The create-nx-workspace command only creates local git repositories
    and does not provide any integration with GitHub for pushing the newly
    created workspace to a remote repository.

    Expected Behavior

    The create-nx-workspace command should offer users the option to
    automatically create a GitHub repository and push their new workspace to
    it using the GitHub CLI (gh), streamlining the workflow from workspace
    creation to remote repository setup.

    Changes Made

    • New Options: Added skipGitHubPush and verbose command-line
      options
    • GitHub Integration: Integrated GitHub repository creation and push
      workflow into the main create-workspace process
    • Interactive Prompts: Added user-friendly prompts for GitHub
      repository creation with validation
    • Async Refactor: Converted git utilities from sync to async/await
      pattern for better error handling
    • Bug Fix: Fixed gh repo create command to include --source flag
      for proper directory specification
    • Error Handling: Added comprehensive error handling with optional
      verbose logging

    Implementation Details

    New CLI Options

    • --skipGitHubPush: Skip pushing to GitHub via gh CLI (default: false)
    • --verbose (-v): Enable verbose logging for detailed error messages

    Workflow Integration

    • After successful git initialization and commit, prompts user if they
      want to push to GitHub
    • Uses gh CLI to authenticate and create repository
    • Provides default repository name format (username/workspace-name)
    • Validates repository name format
    • Handles errors gracefully with helpful fallback instructions

    Technical Changes

    • Refactored git.ts utilities to use execAndWait and spawnAndWait
      for better async handling
    • Added pushToGitHub function with comprehensive error handling
    • Updated CreateWorkspaceOptions interface with new optional
      properties
    • Enhanced command-line argument parsing in yargs-options.ts

    Testing

    The changes maintain backward compatibility - existing workflows
    continue to work unchanged. The new GitHub integration is opt-in and
    gracefully handles cases where:

    • GitHub CLI is not installed
    • User is not authenticated with GitHub
    • Network issues prevent repository creation
    • User chooses not to push to GitHub

    Related Issue(s)

    This PR enhances the user experience by providing seamless integration
    between workspace creation and GitHub repository setup.

    下载附件