-
-
Notifications
You must be signed in to change notification settings - Fork 833
📝 Add docstrings to feature/worktree-ui-config
#465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coderabbitai
wants to merge
1
commit into
develop
Choose a base branch
from
coderabbitai/docstrings/52a4fcc
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+355
−27
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| """ | ||
| Core configuration for Auto Claude. | ||
|
|
||
| This module provides centralized configuration management for Auto Claude, | ||
| including worktree path resolution and validation. It ensures consistent | ||
| configuration access across the entire backend codebase. | ||
|
|
||
| Constants: | ||
| WORKTREE_BASE_PATH_VAR (str): Environment variable name for custom worktree base path. | ||
| DEFAULT_WORKTREE_PATH (str): Default worktree directory name relative to project root. | ||
|
|
||
| Example: | ||
| >>> from core.config import get_worktree_base_path | ||
| >>> from pathlib import Path | ||
| >>> | ||
| >>> # Get worktree path with validation | ||
| >>> project_dir = Path("/path/to/project") | ||
| >>> worktree_path = get_worktree_base_path(project_dir) | ||
| >>> full_path = project_dir / worktree_path | ||
| """ | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| # Environment variable names | ||
| WORKTREE_BASE_PATH_VAR = "WORKTREE_BASE_PATH" | ||
| """str: Environment variable name for configuring custom worktree base path. | ||
|
|
||
| Users can set this environment variable in their project's .env file to specify | ||
| a custom location for worktree directories, supporting both relative and absolute paths. | ||
| """ | ||
|
|
||
| # Default values | ||
| DEFAULT_WORKTREE_PATH = ".worktrees" | ||
| """str: Default worktree directory name. | ||
|
|
||
| This is the fallback value used when WORKTREE_BASE_PATH is not set or when | ||
| validation fails (e.g., path points to .auto-claude/ or .git/ directories). | ||
| """ | ||
|
|
||
|
|
||
| def get_worktree_base_path(project_dir: Path | None = None) -> str: | ||
| """ | ||
| Determine the validated worktree base path from the WORKTREE_BASE_PATH environment variable or the default. | ||
|
|
||
| Parameters: | ||
| project_dir (Path | None): Optional project root used to resolve relative paths and perform stricter validation. If omitted, only basic pattern checks are applied. | ||
|
|
||
| Returns: | ||
| str: The configured worktree base path string, or DEFAULT_WORKTREE_PATH ('.worktrees') if the configured value is invalid or points inside the project's `.auto-claude` or `.git` directories. | ||
| """ | ||
| worktree_base_path = os.getenv(WORKTREE_BASE_PATH_VAR, DEFAULT_WORKTREE_PATH) | ||
|
|
||
| # If no project_dir provided, return as-is (basic validation only) | ||
| if not project_dir: | ||
| # Check for obviously dangerous patterns | ||
| normalized = Path(worktree_base_path).as_posix() | ||
| if ".auto-claude" in normalized or ".git" in normalized: | ||
| return DEFAULT_WORKTREE_PATH | ||
| return worktree_base_path | ||
|
|
||
| # Resolve the absolute path | ||
| if Path(worktree_base_path).is_absolute(): | ||
| resolved = Path(worktree_base_path).resolve() | ||
| else: | ||
| resolved = (project_dir / worktree_base_path).resolve() | ||
|
|
||
| # Prevent paths inside .auto-claude/ or .git/ | ||
| auto_claude_dir = (project_dir / ".auto-claude").resolve() | ||
| git_dir = (project_dir / ".git").resolve() | ||
|
|
||
| resolved_str = str(resolved) | ||
| if resolved_str.startswith(str(auto_claude_dir)) or resolved_str.startswith( | ||
| str(git_dir) | ||
| ): | ||
| return DEFAULT_WORKTREE_PATH | ||
|
|
||
| return worktree_base_path | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,9 +53,22 @@ | |
| """ | ||
|
|
||
| def __init__(self, project_dir: Path, base_branch: str | None = None): | ||
| """ | ||
| Initialize the WorktreeManager for a repository, determining base branch and worktrees directory. | ||
|
|
||
| Parameters: | ||
| project_dir (Path): Root path of the repository managed by this instance. | ||
| base_branch (str | None): Optional explicit base branch to use; if omitted, the base branch is auto-detected. | ||
| """ | ||
| from core.config import get_worktree_base_path | ||
|
|
||
| self.project_dir = project_dir | ||
| self.base_branch = base_branch or self._detect_base_branch() | ||
| self.worktrees_dir = project_dir / ".worktrees" | ||
|
|
||
| # Use custom worktree path from environment variable with validation | ||
| worktree_base_path = get_worktree_base_path(project_dir) | ||
| self.worktrees_dir = project_dir / worktree_base_path | ||
|
|
||
| self._merge_lock = asyncio.Lock() | ||
|
|
||
| def _detect_base_branch(self) -> str: | ||
|
|
@@ -664,4 +677,4 @@ | |
|
|
||
|
|
||
| # Keep STAGING_WORKTREE_NAME for backward compatibility in imports | ||
| STAGING_WORKTREE_NAME = "auto-claude" | ||
| STAGING_WORKTREE_NAME = "auto-claude" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,10 @@ import { AVAILABLE_MODELS } from '../../../shared/constants'; | |
| import type { | ||
| Project, | ||
| ProjectSettings as ProjectSettingsType, | ||
| AutoBuildVersionInfo | ||
| AutoBuildVersionInfo, | ||
| ProjectEnvConfig | ||
| } from '../../../shared/types'; | ||
| import { WorktreeSettings } from './WorktreeSettings'; | ||
|
|
||
| interface GeneralSettingsProps { | ||
| project: Project; | ||
|
|
@@ -32,16 +34,34 @@ interface GeneralSettingsProps { | |
| isCheckingVersion: boolean; | ||
| isUpdating: boolean; | ||
| handleInitialize: () => Promise<void>; | ||
| envConfig: ProjectEnvConfig | null; | ||
| updateEnvConfig: (updates: Partial<ProjectEnvConfig>) => void; | ||
| } | ||
|
|
||
| /** | ||
| * Render general project settings, including auto-build integration, agent configuration, worktree location, and notification toggles. | ||
| * | ||
| * @param project - Project data used to determine auto-build state and provide paths. | ||
| * @param settings - Current project settings that drive form controls and toggles. | ||
| * @param setSettings - State updater used to replace the project settings object. | ||
| * @param versionInfo - Optional auto-build version and initialization status displayed when available. | ||
| * @param isCheckingVersion - When true, displays a loading indicator while checking auto-build status. | ||
| * @param isUpdating - When true, disables initialization controls and shows an initializing state. | ||
| * @param handleInitialize - Called to initialize the auto-build integration. | ||
| * @param envConfig - Optional environment configuration passed into worktree settings. | ||
| * @param updateEnvConfig - Function to apply partial updates to the environment configuration. | ||
| * @returns The rendered settings UI as JSX. | ||
| */ | ||
| export function GeneralSettings({ | ||
| project, | ||
| settings, | ||
| setSettings, | ||
| versionInfo, | ||
| isCheckingVersion, | ||
| isUpdating, | ||
| handleInitialize | ||
| handleInitialize, | ||
| envConfig, | ||
| updateEnvConfig | ||
| }: GeneralSettingsProps) { | ||
| const { t } = useTranslation(['settings']); | ||
|
|
||
|
|
@@ -150,6 +170,18 @@ export function GeneralSettings({ | |
|
|
||
| <Separator /> | ||
|
|
||
| {/* Worktree Location */} | ||
| <section className="space-y-4"> | ||
| <h3 className="text-sm font-semibold text-foreground">{t('projectSections.worktree.title')}</h3> | ||
| <WorktreeSettings | ||
| envConfig={envConfig} | ||
| updateEnvConfig={updateEnvConfig} | ||
| projectPath={project.path} | ||
| /> | ||
| </section> | ||
|
|
||
| <Separator /> | ||
|
|
||
| {/* Notifications */} | ||
| <section className="space-y-4"> | ||
| <h3 className="text-sm font-semibold text-foreground">Notifications</h3> | ||
|
|
@@ -220,4 +252,4 @@ export function GeneralSettings({ | |
| )} | ||
| </> | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused import Note
Copilot Autofix
AI 5 days ago
To fix the problem, remove the unused
osimport fromapps/backend/cli/batch_commands.py. In general terms, unused imports should be deleted to keep the code clean, avoid confusion about dependencies, and slightly reduce module load overhead.In this specific case, edit
apps/backend/cli/batch_commands.pynear the top of the file. Delete the lineimport osat line 9, leaving the remaining imports (json,Path, andfrom ui import highlight, print_status) unchanged. No additional methods, imports, or definitions are required; this is a simple deletion that does not alter runtime behavior sinceosis not referenced in the shown code.