Handles all web routes for the application.
| 23 | |
| 24 | |
| 25 | class WebRoutes: |
| 26 | """Handles all web routes for the application.""" |
| 27 | |
| 28 | def __init__(self, background_worker: BackgroundWorker, cache_manager: CacheManager): |
| 29 | self.background_worker = background_worker |
| 30 | self.cache_manager = cache_manager |
| 31 | |
| 32 | async def index_get(self, request: Request) -> HTMLResponse: |
| 33 | """Main page with form for submitting GitHub repositories.""" |
| 34 | # Clean up old jobs before displaying |
| 35 | # self.cleanup_old_jobs() |
| 36 | |
| 37 | # Get recent jobs (last 10) |
| 38 | all_jobs = self.background_worker.get_all_jobs() |
| 39 | recent_jobs = sorted( |
| 40 | all_jobs.values(), |
| 41 | key=lambda x: x.created_at, |
| 42 | reverse=True |
| 43 | )[:100] |
| 44 | |
| 45 | context = { |
| 46 | "message": None, |
| 47 | "message_type": None, |
| 48 | "repo_url": "", |
| 49 | "commit_id": "", |
| 50 | "recent_jobs": recent_jobs |
| 51 | } |
| 52 | |
| 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) |