Handle repository submission.
(self, request: Request, repo_url: str = Form(...), commit_id: str = Form(""))
| 53 | return HTMLResponse(content=render_template(WEB_INTERFACE_TEMPLATE, context)) |
| 54 | |
| 55 | async def index_post(self, request: Request, repo_url: str = Form(...), commit_id: str = Form("")) -> HTMLResponse: |
| 56 | """Handle repository submission.""" |
| 57 | # Clean up old jobs before processing |
| 58 | self.cleanup_old_jobs() |
| 59 | |
| 60 | message = None |
| 61 | message_type = None |
| 62 | |
| 63 | repo_url = repo_url.strip() |
| 64 | commit_id = commit_id.strip() if commit_id else "" |
| 65 | |
| 66 | if not repo_url: |
| 67 | message = "Please enter a GitHub repository URL" |
| 68 | message_type = "error" |
| 69 | elif not GitHubRepoProcessor.is_valid_github_url(repo_url): |
| 70 | message = "Please enter a valid GitHub repository URL" |
| 71 | message_type = "error" |
| 72 | else: |
| 73 | # Normalize the repo URL for comparison |
| 74 | normalized_repo_url = self._normalize_github_url(repo_url) |
| 75 | |
| 76 | # Get repo info for job ID generation |
| 77 | repo_info = GitHubRepoProcessor.get_repo_info(normalized_repo_url) |
| 78 | job_id = self._repo_full_name_to_job_id(repo_info['full_name']) |
| 79 | |
| 80 | # Check if already in queue, processing, or recently failed |
| 81 | existing_job = self.background_worker.get_job_status(job_id) |
| 82 | recent_cutoff = datetime.now() - timedelta(minutes=WebAppConfig.RETRY_COOLDOWN_MINUTES) |
| 83 | |
| 84 | if existing_job: |
| 85 | if existing_job.status in ['queued', 'processing']: |
| 86 | pass # Will handle below |
| 87 | elif existing_job.status == 'failed' and existing_job.created_at > recent_cutoff: |
| 88 | pass # Will handle below |
| 89 | else: |
| 90 | existing_job = None # Job is old or completed, can reuse |
| 91 | |
| 92 | if existing_job: |
| 93 | if existing_job.status in ['queued', 'processing']: |
| 94 | message = f"Repository is already being processed (Job ID: {existing_job.job_id})" |
| 95 | else: |
| 96 | message = f"Repository recently failed processing. Please wait a few minutes before retrying (Job ID: {existing_job.job_id})" |
| 97 | message_type = "error" |
| 98 | else: |
| 99 | # Check cache |
| 100 | cached_docs = self.cache_manager.get_cached_docs(normalized_repo_url) |
| 101 | if cached_docs and Path(cached_docs).exists(): |
| 102 | message = "Documentation found in cache! Redirecting to view..." |
| 103 | message_type = "success" |
| 104 | # Create a dummy completed job for display |
| 105 | job = JobStatus( |
| 106 | job_id=job_id, |
| 107 | repo_url=normalized_repo_url, # Use normalized URL |
| 108 | status='completed', |
| 109 | created_at=datetime.now(), |
| 110 | completed_at=datetime.now(), |
| 111 | docs_path=cached_docs, |
| 112 | progress="Retrieved from cache", |
no test coverage detected