Skip to content

Commit 1256c06

Browse files
authored
Add GitHub PR Clone (#2)
* git commit -m "Add PR clone functionality and refactor codebase - Add PR Clone webview with React components for GitHub PR cloning - Remove TestWebViewProvider and consolidate to PR-focused functionality - Add command palette integration for "Clone pull request..." command - Rename cherry.svg icons to clone.svg to better reflect functionality - Configure activity bar to show/hide based on PR clone context - Add ESLint ignore patterns for TypeScript declaration files - Update build configuration for webview compilation * Refactor webview components and add notification system - Restructure React components into proper pages and components folders - Add reusable Button and DropDownButton components with CSS modules - Move component-specific styles to individual CSS module files - Add notification system for PR fetch success messages - Improve global CSS and remove unused type definitions - Add linting configuration with .hintrc * Refactoring and tune project * Refactor code structure for improved readability and maintainability * Refactor Button and Text components; add Label variant and improve Textarea styles * feat: Implement PR cloning and commit selection functionality - Added data types for GitHub PRs and commits in `dataTypes.ts`. - Created `PrCommitsWebViewProvider` to manage the display and selection of commits related to a PR. - Introduced `PrCloneWebViewProvider` to handle the PR cloning process and integrate with the commits webview. - Developed the `CommitsApp` component to display and manage commit selection. - Implemented the `PrCloneForm` and `PrInputForm` components for user input and PR fetching. - Added new components for buttons, dropdowns, inputs, links, and text areas to enhance UI. - Updated CSS styles for better visual integration and user experience. - Configured Webpack to handle multiple entry points for the main and commits webviews. * chore: Update .gitignore and .vscodeignore; remove TODO.md * feat: Enhance DropDownButton with loading state and action selection; refactor related components and styles * Implement TypeScript checks, refactor PR commits handling, and enhance GitHub API integration - Added a new script `hooks/tsc.js` to run TypeScript checks for main and webview projects. - Updated `package.json` to change the type of "Commits to Cherry-pick" from webview to tree and added a new command for toggling commit selection. - Introduced new SVG icons for UI enhancements: `chevron-down.svg`, `chevron-right.svg`, `commit.svg`, and `spinner.svg`. - Created `src/common/api/ghClient.ts` to handle GitHub API requests, including fetching pull request and commit details. - Refactored `src/extension.ts` to integrate the new `PrCommitsTreeProvider` and replace the old webview provider. - Updated data types in `src/types/dataTypes.ts` to include additional fields for commit files and application state. - Developed `src/view/PrCommitsTreeProvider.ts` to manage commit selection in a tree view format, replacing the previous webview implementation. - Removed the old `PrCommitsWebViewProvider.ts` and associated webview files, streamlining the codebase. - Adjusted `src/webview/commits-template.html` and related React components to reflect the new tree view structure. - Updated TypeScript configuration to include new paths for types. - Modified Webpack configuration to remove the old commits entry point and associated HTML template. * feat: Implement logging service and integrate with webview; refactor app structure and remove unused components * feat: Add command to copy commits to clipboard; update settings and enhance PrCommitsTreeProvider * feat: Add default target branch configuration and enhance PR cloning functionality - Introduced `defaultTargetBranch` configuration option in `ConfigurationManager` and `ExtensionConfig`. - Updated `PrCloneWebViewProvider` to utilize the default target branch from configuration. - Implemented `PrCloneService` to handle the cloning of pull requests, including cherry-picking selected commits and creating a new PR. - Enhanced user experience by adding loading states and disabling actions during cloning. - Added commands to select and deselect all commits in the `PrCommitsTreeProvider`. - Improved logging throughout the application for better debugging and tracking. - Updated webview components to reflect changes in state and configuration. * Refactor code structure for improved readability and maintainability, switch to web view instead of TreeView * feat: Enhance PR cloning process with confirmation dialog and branch cleanup; refactor commit display components for improved styling * feat: Add GitExecutor methods for branch management and enhance PR cloning service with cancellation support and improved error handling * fix: Remove default PR input value for improved user experience * Refactor webview components to use module.css naming convention and improve code organization - Changed CSS module imports to use 'module.css' naming convention across various components. - Created new CSS modules for CommitFileItem, CommitItem, CommitsList, DropDownButton, Input, Link, LoadingSpinner, Text, Textarea, and PrCloneForm. - Introduced a new utility function `extractCommitInfo` to encapsulate commit information extraction logic. - Implemented a new hook `useSendMessage` to streamline message sending to the VS Code extension. - Updated message handling in App and PrCloneForm components to utilize the new `useSendMessage` hook. - Added a new commands type definition file to standardize command strings used in communication between the webview and the extension. - Removed deprecated CSS files and cleaned up unused code. * fix circular dependency * Refactor web react apps and update file structure * feat: Enhance notification and confirmation dialogs with additional details and improve commit status handling, join commands.ts and webviewCommands.ts with symlink * feat: Add branch existence checks and improve cherry-pick error handling; enhance input component with focus and escape key functionality * feat: Add fetchSpecificBranch method to GitExecutor and integrate it into PRCloneWebViewProvider for fetching latest changes * feat: Implement in-place cherry-pick option and enhance PR cloning process with configuration support * feat: Refactor GitExecutor to use SimpleGit for improved command execution and add new utility functions; remove unused execCommand and createPromiseWithResolvers utilities * Revert "feat: Refactor GitExecutor to use SimpleGit for improved command execution and add new utility functions; remove unused execCommand and createPromiseWithResolvers utilities" This reverts commit d94ef76. * feat: Add PR clone cancellation and conflicts resolved commands; update package.json for new menu items * feat: Implement in-place PR cloning functionality - Added `PrCloneServiceBase` as an abstract class for PR cloning services. - Introduced `PrCloneTempWorktreeService` for cloning PRs using temporary worktrees. - Created utility functions for managing progress and context in the VSCode extension. - Implemented `CommitsGenerator` for sorting and iterating over commits. - Enhanced `PrCloneWebViewProvider` and `PrCommitsWebViewProvider` to handle new cloning features and context updates. - Updated webview components to reflect changes in repo information and cloning state. - Added error handling and cleanup mechanisms for cloning operations. - Refactored existing code for better organization and maintainability. * feat: Refactor PR cloning process to improve state management and update loading indicators * feat: Update cloning state management in PR cloning process; refactor related methods and add skip icon * feat: Add GitHub API version header and enhance cherry-pick handling; update PR creation process * feat: Add GitHub PR Clone feature with branch prefix configuration; enhance related components and UI * fix: Update command category for PR cloning to GitHub in README and package.json
1 parent 2de775c commit 1256c06

95 files changed

Lines changed: 13532 additions & 105 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Create component in directory src/webview/components for: $ARGUMENTS
2+
3+
Component conventions:
4+
5+
- Create the component in own directory, name the directory as component name
6+
- Place component and prop type in file index.tsx
7+
- Create styles in module.css file according to component name
8+
- If there are additional types needed by the component, put these types in the same directory in file types.ts
9+
- verify other components are following these conventions, if not following, update these components to meet above requirements

.claude/commands/refactor.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Refactor $ARGUMENTS
2+
3+
Align component according to following conventions:
4+
5+
- One component in own directory, name the directory as component name
6+
- Place component and prop type in file index.tsx, avoid using content of component in file that is named as component, use only index.tsx
7+
- Create styles in module.css file according to component name
8+
- verify that there are no unused styles in \*.module.css files
9+
- if a css class has some pseudoclasses attached, prefer to use & syntax e.g., for example for class '.someStyle':
10+
.someStyle {
11+
display: block;
12+
13+
&:hover {
14+
color: red;
15+
}
16+
}
17+
18+
- verify other components are following these conventions, if not following, update these components to meet above requirements
19+
- if there is a potential code duplication, add TODO comment that indicates teh duplication and refer to place in code where is the another duplication
20+
- verify all imports work as before the changes
21+
- for colors in *.css files use only vscode specific colors e.g. with prefix --vscode-

.claude/settings.local.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"mcp__playwright",
5+
"Bash(find:*)",
6+
"Bash(yarn check-types)",
7+
"Bash(yarn lint)",
8+
"Bash(mv:*)",
9+
"Bash(mkdir:*)",
10+
"Bash(yarn tsc:*)",
11+
"Bash(rm:*)",
12+
"mcp__ide__getDiagnostics",
13+
"Bash(yarn serve-webview:*)",
14+
"Bash(yarn install)",
15+
"Bash(timeout:*)",
16+
"Bash(yarn build-webview:*)",
17+
"Bash(yarn check-types-webview:*)",
18+
"WebFetch(domain:code.visualstudio.com)",
19+
"Bash(yarn compile)",
20+
"Bash(grep:*)"
21+
],
22+
"deny": []
23+
},
24+
"enableAllProjectMcpServers": false,
25+
"hooks": {
26+
"PostToolUse": [
27+
{
28+
"matcher": "Write|MultiEdit|Edit",
29+
"hooks": [
30+
{
31+
"type": "command",
32+
"command": "node $PWD/hooks/tsc.js"
33+
},
34+
{
35+
"type": "command",
36+
"command": "node $PWD/hooks/lint.js"
37+
}
38+
]
39+
},
40+
{
41+
"matcher": "*",
42+
"hooks": [
43+
{
44+
"type": "command",
45+
"command": "jq . > post-log.json"
46+
}
47+
]
48+
}
49+
]
50+
}
51+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ node_modules
99
coverage/
1010
**/*.map
1111
.vscode-test-web/
12+
post-log.json
13+
*.tsbuildinfo
14+
TODO*

.hintrc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"extends": [
3+
"development"
4+
],
5+
"hints": {
6+
"compat-api/css": [
7+
"default",
8+
{
9+
"ignore": [
10+
"overscroll-behavior-x",
11+
"overscroll-behavior-x: none"
12+
]
13+
}
14+
]
15+
},
16+
"browserslist": [
17+
"defaults",
18+
"not ie 11",
19+
"not and_ff <= 126",
20+
"not firefox <= 126",
21+
"not ios_saf <= 17.5",
22+
"not safari <= 17.5"
23+
]
24+
}

.vscode/launch.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55
"name": "Run Extension",
66
"type": "extensionHost",
77
"request": "launch",
8-
"args": ["--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}"],
9-
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
10-
"preLaunchTask": "${defaultBuildTask}"
11-
},
12-
{
13-
"name": "Extension Tests",
14-
"type": "extensionHost",
15-
"request": "launch",
168
"args": [
9+
// "--disable-extensions",
10+
"--profile \"Debug\"", //Debug profile with only necessary plugins for debug
1711
"--extensionDevelopmentPath=${workspaceFolder}",
18-
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
12+
"/Users/valentineradchuk/Dev/aura/gh-mindsight"
1913
],
20-
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
21-
"preLaunchTask": "npm: watch-tests"
14+
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
15+
"preLaunchTask": "${defaultBuildTask}"
2216
}
2317
]
2418
}

.vscode/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"typescript.preferences.includePackageJsonAutoImports": "auto",
3+
"typescript.suggest.autoImports": true,
4+
"typescript.preferences.useLabelDetailsInCompletionEntries": true,
5+
"files.associations": {
6+
"*.module.css": "css"
7+
},
8+
"css.customData": [],
9+
"typescript.tsc.autoDetect": "on",
10+
"typescript.disableAutomaticTypeAcquisition": false,
11+
"typescript.enablePromptUseWorkspaceTsdk": true,
12+
"typescript.surveys.enabled": false,
13+
"typescript.preferences.experimentalDecorators": "auto",
14+
"typescript.workspaceSymbols.scope": "allOpenProjects"
15+
}

.vscode/tasks.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@
3535
"group": "watchers"
3636
},
3737
"group": "build"
38+
},
39+
{
40+
"type": "npm",
41+
"script": "watch-webview",
42+
"problemMatcher": "$tsc-watch",
43+
"isBackground": true,
44+
"presentation": {
45+
"reveal": "never",
46+
"group": "watchers"
47+
},
48+
"group": "build",
49+
"runOptions": {
50+
"runOn": "folderOpen"
51+
}
3852
}
3953
]
4054
}

.vscodeignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ vsc-extension-quickstart.md
1515
**/esbuild.*js
1616
**/eslint.config.*js
1717
.prettier*
18+
**/*.tsbuildinfo
19+
**/*.config.*js*
20+
TODO.md

CLAUDE.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Development Commands
6+
7+
### Build and Development
8+
9+
- `yarn compile` - Compile TypeScript and run lint checks
10+
- `yarn watch` - Start development with file watching (runs both esbuild and TypeScript compiler)
11+
- `yarn package` - Build for production (includes type checking and linting)
12+
- `yarn check-types` - Run TypeScript type checking without emitting files
13+
- `yarn lint` - Run ESLint on source files
14+
15+
### Testing
16+
17+
- `yarn test` - Run all tests (includes compilation and linting)
18+
- `yarn compile-tests` - Compile test files only
19+
- `yarn watch-tests` - Watch and compile tests
20+
21+
### Webview Development
22+
23+
- `yarn dev` - Start both extension watcher and webview dev server with HMR (recommended for development)
24+
- `yarn serve-webview` - Start webpack dev server for hot reload during webview development
25+
- `yarn build-webview` - Build webview for production
26+
- `yarn watch-webview` - Watch and build webview for development (without HMR)
27+
- `yarn check-types-webview` - Run TypeScript type checking for webview files
28+
29+
### Hot Module Replacement (HMR)
30+
31+
The webview supports hot reloading during development:
32+
33+
1. Run `yarn dev` to start both extension compilation and webview dev server
34+
2. Launch VS Code extension (F5) - the webview will automatically detect development mode
35+
3. Edit any webview React components in `src/webview/` - changes will hot reload instantly
36+
4. The extension uses `context.extensionMode` to detect development vs production
37+
38+
### Extension Packaging
39+
40+
- `yarn build-vsix` - Build production VSIX package
41+
- `yarn build-vsix-dev` - Build development VSIX without dependencies
42+
- `yarn publish` - Publish to VS Code marketplace
43+
44+
## Code Architecture
45+
46+
### Extension Structure
47+
48+
This is a VS Code extension that provides intelligent Git checkout functionality with automatic stashing. The extension follows a modular architecture with clear separation of concerns:
49+
50+
**Core Components:**
51+
52+
- `CommandManager` - Centralized command registration and error handling
53+
- `ConfigurationManager` - Manages VS Code settings and user preferences
54+
- `StatusBarManager` - Handles the status bar display showing current stash mode
55+
- `LoggingService` - Centralized logging with configurable output
56+
- `PrCloneWebViewProvider` - PR Clone webview for GitHub pull request operations
57+
58+
### Command Pattern Implementation
59+
60+
All commands implement the `ICommand` interface and are registered through the `CommandManager`. This provides consistent error handling and makes commands easily testable. Each command is in its own directory under `src/commands/`.
61+
62+
### Configuration System
63+
64+
The extension uses a layered configuration approach:
65+
66+
- VS Code workspace settings via `ConfigurationManager`
67+
- Real-time configuration updates through `onDidChangeConfiguration`
68+
- Global configuration persistence for user preferences
69+
70+
### Git Integration
71+
72+
Git operations are abstracted through `GitExecutor` in `src/common/git/`, which provides:
73+
74+
- Promise-based command execution
75+
- Consistent error handling
76+
- Type-safe Git operation interfaces
77+
78+
### Stash Modes
79+
80+
The extension supports multiple auto-stash strategies:
81+
82+
- **Manual**: User chooses stash behavior each time
83+
- **Auto stash in current branch**: Creates branch-specific stashes
84+
- **Auto stash and pop**: Transfers changes to new branch (destructive)
85+
- **Auto stash and apply**: Transfers changes while preserving original stash
86+
87+
### WebView Integration
88+
89+
The extension provides two collapsible webviews for PR cloning functionality:
90+
91+
1. **PR Clone WebView** (`PrCloneWebViewProvider`): Main form with branch selection, feature branch name, and description fields. Contains Cancel and Create buttons.
92+
93+
2. **PR Commits WebView** (`PrCommitsWebViewProvider`): Separate webview displaying the list of commits to cherry-pick. Users can select/deselect commits independently.
94+
95+
Both webviews communicate through VS Code commands and message passing. The commits webview has a transparent background to integrate seamlessly with VS Code's theme. The webpack configuration generates separate bundles (`main.js` and `commits.js`) for each webview.
96+
97+
### Build System
98+
99+
Uses esbuild for fast bundling with a custom problem matcher plugin for VS Code integration. The build outputs to `dist/extension.js` as a CommonJS bundle with VS Code as an external dependency.
100+
101+
### Extension Manifest
102+
103+
Key package.json contributions:
104+
105+
- Activity bar container: `git-smart-checkout`
106+
- PR Clone view: `git-smart-checkout.prClone` (conditionally shown)
107+
- Commands: checkout, pull-with-stash, switch-mode, clone-pull-request
108+
- Configuration properties for stash modes and logging
109+
110+
## Important Development Notes
111+
112+
### Command Registration
113+
114+
When adding new commands, register them in `extension.ts` using the `CommandManager` pattern and ensure they implement the `ICommand` interface.
115+
116+
### Configuration Changes
117+
118+
New settings must be added to both `package.json` contributions and the `ExtensionConfig` interface in `src/configuration/extensionConfig.ts`.
119+
120+
### Git Operations
121+
122+
All Git commands should go through `GitExecutor` for consistency. The utility functions in `src/commands/utils/` provide common Git operations like branch listing and stash message formatting.
123+
124+
### WebView Updates
125+
126+
The WebView provider creates HTML with VS Code CSS variables for proper theming. Message handling between WebView and extension happens through `onDidReceiveMessage`.
127+
128+
## React Development Guidelines
129+
130+
- When creating React components, create them in a separate folder along with own CSS module file, and add styles related to this component to neighbour CSS module file, avoid using global CSS file unless it's necessary
131+
- When adding or editing a React component, order imports in the following order:
132+
1. npm dependencies (with 'react' always first, if required by the component)
133+
2. Project dependencies (separated by an empty line from npm dependencies)
134+
3. Local dependencies from the same or nearby directories (separated by an empty line from project dependencies)

0 commit comments

Comments
 (0)