-
feat(core): add GitHub repository creation and push functionality (#31936)
发布于
2025-07-18 03:41:36 +00:00 Current Behavior
The
create-nx-workspacecommand 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-workspacecommand 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
skipGitHubPushandverbosecommand-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 createcommand to include--sourceflag
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
ghCLI 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.tsutilities to useexecAndWaitandspawnAndWait
for better async handling - Added
pushToGitHubfunction with comprehensive error handling - Updated
CreateWorkspaceOptionsinterface 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.下载附件
- New Options: Added