update PR logic
Browse filesFiles changed (4)
196 unmodified lines197198199200201202203645 unmodified lines849850851851852853854855856857853858859860861196 unmodified lines history: List[List[str]] = [] agent_mode: bool = False existing_repo_id: Optional[str] = None # For auto-deploy to update existing space skip_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) # 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_")): if auth.is_authenticated() and not (auth.token and auth.token.startswith("dev_token_")) and not request.skip_auto_deploy: try: # Send deploying status deploying_data = json.dumps({1398 unmodified lines13991400140114021402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714101411141214281429143014311432143314151416141714181419142014211422142314241425143414351436142814371438143914401398 unmodified lines file_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=True # Create PR using the correct API flow: # 1. Create discussion with pull_request=True # 2. Add commits to the PR branch try: 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 discussion token=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 name pr_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=pr_title, commit_description=pr_description, create_pr=True # This creates a PR instead of direct commit commit_message=f"{pr_title} (files)", commit_description="Updated files for redesign", revision=pr_branch, # Commit to the PR branch token=token ) # Extract PR URL from commit_info pr_url = commit_info.pr_url if hasattr(commit_info, 'pr_url') else None if not pr_url: # Fallback: construct PR URL from pr_num if available pr_num = commit_info.pr_num if hasattr(commit_info, 'pr_num') else None if 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}" success_msg = f"✅ Pull Request created! View at: {discussion.url}" print(f"[PR] {success_msg}") return True, success_msg, pr_url return True, success_msg, discussion.url except Exception as e: print(f"[PR] Error creating pull request: {e}")300 unmodified lines301302303304305306307300 unmodified lines history: messages.map((m) => [m.role, m.content]), agent_mode: false, existing_repo_id: effectiveRepoId, // Pass duplicated/imported space ID for auto-deploy skip_auto_deploy: !!pendingPR, // Skip auto-deploy if PR is pending };
const assistantMessage: Message = {19 unmodified lines2021222324252619 unmodified lines history: string[][]; agent_mode: boolean; existing_repo_id?: string; // For auto-deploy to update existing space skip_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