# Smart Git URL Parsing - Tasks

## Phase 1: Backend URL Parsing

- [ ] **Task 1.1**: Create URL parsing utilities
  - Create `src/utils/git_url_parser.py`
  - Implement `extract_base_repo_url()` function
  - Support GitHub, GitLab, Bitbucket patterns
  - Handle query parameters, branch paths, file paths
  - Add comprehensive unit tests

- [ ] **Task 1.2**: Create URL validation endpoint
  - Add `POST /git-repositories/parse-url` endpoint
  - Returns URLParseResult with original, base, validation status
  - Add tests for endpoint

- [ ] **Task 1.3**: Enhance repository creation endpoint
  - Update `POST /projects/{project_id}/repositories`
  - Detect browser URLs and return 422 with suggestion
  - Add `force_original_url` flag to bypass suggestion
  - Update response models

## Phase 2: Frontend Implementation

- [ ] **Task 2.1**: Create API client for URL parsing
  - Add `parseGitUrl()` function to `api/git_repositories.ts`
  - Add types for URLParseResult

- [ ] **Task 2.2**: Enhance repository creation form
  - Add real-time URL validation to input field
  - Show visual indicators (green/yellow/red)
  - Display inline suggestion banner
  - Add "Use Suggested" / "Keep Original" buttons

- [ ] **Task 2.3**: Create confirmation dialog
  - Create `URLCorrectionDialog` component
  - Shows original vs suggested URL comparison
  - Handles accept/reject/cancel actions
  - Integrate with repository creation flow

## Phase 3: Integration & Testing

- [ ] **Task 3.1**: Wire up frontend to backend
  - Call parse-url endpoint on URL input change (debounced)
  - Handle 422 responses from repository creation
  - Show confirmation dialog when needed

- [ ] **Task 3.2**: Add error handling
  - Handle network errors during URL validation
  - Show clear error messages for unsupported URLs
  - Handle clone failures gracefully

- [ ] **Task 3.3**: Run quality gates
  - Backend: ruff, mypy, pytest
  - Frontend: typecheck, lint, build

- [ ] **Task 3.4**: Manual testing
  - Test with GitHub URLs (tree, blob, pull)
  - Test with GitLab URLs (-/tree, -/blob)
  - Test with valid git URLs (should pass through)
  - Test force_original_url flag
