update PR logic
Browse filesFiles changed (4)
196 unmodified lines197198199200201202645 unmodified lines848849850851852853854855856196 unmodified lineshistory: List[List[str]] = []agent_mode: bool = Falseexisting_repo_id: Optional[str] = None # For auto-deploy to update existing spaceclass DeploymentRequest(BaseModel):645 unmodified lines})yield f"data: {completion_data}\n\n"# Auto-deploy after code generation (if authenticated)auth = get_auth_from_header(authorization)if auth.is_authenticated() and not (auth.token and auth.token.startswith("dev_token_")):try:# Send deploying statusdeploying_data = json.dumps({196 unmodified lines197198199200201202203645 unmodified lines849850851852853854855856857858859860861196 unmodified lineshistory: List[List[str]] = []agent_mode: bool = Falseexisting_repo_id: Optional[str] = None # For auto-deploy to update existing spaceskip_auto_deploy: bool = False # Skip auto-deploy (for PR creation)class DeploymentRequest(BaseModel):645 unmodified lines})yield f"data: {completion_data}\n\n"# Auto-deploy after code generation (if authenticated and not skipped)auth = get_auth_from_header(authorization)if request.skip_auto_deploy:print(f"[Auto-Deploy] Skipped - PR creation will be handled by frontend")if auth.is_authenticated() and not (auth.token and auth.token.startswith("dev_token_")) and not request.skip_auto_deploy:try:# Send deploying statusdeploying_data = json.dumps({
1398 unmodified lines1399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311398 unmodified linesfile_path.parent.mkdir(parents=True, exist_ok=True)file_path.write_text(content, encoding='utf-8')# Upload files and create PR using create_commit with create_pr=Truetry:print(f"[PR] Creating pull request on {repo_id}")commit_info = api.upload_folder(folder_path=str(temp_path),repo_id=repo_id,repo_type="space",commit_message=pr_title,commit_description=pr_description,create_pr=True # This creates a PR instead of direct commit)# Extract PR URL from commit_infopr_url = commit_info.pr_url if hasattr(commit_info, 'pr_url') else Noneif not pr_url:# Fallback: construct PR URL from pr_num if availablepr_num = commit_info.pr_num if hasattr(commit_info, 'pr_num') else Noneif pr_num:pr_url = f"https://huggingface.co/spaces/{repo_id}/discussions/{pr_num}"else:pr_url = f"https://huggingface.co/spaces/{repo_id}/discussions"success_msg = f"✅ Pull Request created! View at: {pr_url}"print(f"[PR] {success_msg}")return True, success_msg, pr_urlexcept Exception as e:print(f"[PR] Error creating pull request: {e}")1398 unmodified lines1399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401398 unmodified linesfile_path.parent.mkdir(parents=True, exist_ok=True)file_path.write_text(content, encoding='utf-8')# Create PR using the correct API flow:# 1. Create discussion with pull_request=True# 2. Add commits to the PR branchtry:print(f"[PR] Creating pull request on {repo_id}")# Step 1: Create the PR (draft mode)discussion = api.create_discussion(repo_id=repo_id,title=pr_title,description=pr_description,repo_type="space",pull_request=True, # This makes it a PR instead of discussiontoken=token)print(f"[PR] Created PR #{discussion.num}: {discussion.url}")# Step 2: Upload files to the PR branch# The PR branch is automatically created and has a specific namepr_branch = f"refs/pr/{discussion.num}"commit_info = api.upload_folder(folder_path=str(temp_path),repo_id=repo_id,repo_type="space",commit_message=f"{pr_title} (files)",commit_description="Updated files for redesign",revision=pr_branch, # Commit to the PR branchtoken=token)success_msg = f"✅ Pull Request created! View at: {discussion.url}"print(f"[PR] {success_msg}")return True, success_msg, discussion.urlexcept Exception as e:print(f"[PR] Error creating pull request: {e}")
300 unmodified lines301302303304305306300 unmodified lineshistory: messages.map((m) => [m.role, m.content]),agent_mode: false,existing_repo_id: effectiveRepoId, // Pass duplicated/imported space ID for auto-deploy};const assistantMessage: Message = {300 unmodified lines301302303304305306307300 unmodified lineshistory: messages.map((m) => [m.role, m.content]),agent_mode: false,existing_repo_id: effectiveRepoId, // Pass duplicated/imported space ID for auto-deployskip_auto_deploy: !!pendingPR, // Skip auto-deploy if PR is pending};const assistantMessage: Message = {
19 unmodified lines20212223242519 unmodified lineshistory: string[][];agent_mode: boolean;existing_repo_id?: string; // For auto-deploy to update existing space}export interface CodeGenerationResponse {19 unmodified lines2021222324252619 unmodified lineshistory: string[][];agent_mode: boolean;existing_repo_id?: string; // For auto-deploy to update existing spaceskip_auto_deploy?: boolean; // Skip auto-deploy (for PR creation)}export interface CodeGenerationResponse {
backend_api.py+7-2
backend_deploy.py+25-16
frontend/src/app/page.tsx+1
frontend/src/types/index.ts+1