update
Browse files1398 unmodified lines1399140014011402140314041402140314041406140514061408140914101411141214131414141514071408140914101417141114121413141414151416141714181419142014191420142114211422142314241423142414251426142714281429142714281429143014311432143314331434143414351436143714381439144014411442144314441445143614461447144814491398 unmodified lines file_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 PR with create_pull_request() # 2. Add commits to the PR branch # Create PR with files using create_commit (recommended approach) # This creates the PR and uploads files in one API call try: print(f"[PR] Creating pull request on {repo_id}") print(f"[PR] Creating pull request with files on {repo_id}") # Step 1: Create the PR (draft mode) using the wrapper function discussion = api.create_pull_request( repo_id=repo_id, title=pr_title, description=pr_description, repo_type="space", token=token ) # Prepare operations for all files from huggingface_hub import CommitOperationAdd operations = [] print(f"[PR] Created PR #{discussion.num}: {discussion.url}") for file_path in temp_path.rglob('*'): if file_path.is_file(): rel_path = file_path.relative_to(temp_path) operations.append( CommitOperationAdd( path_in_repo=str(rel_path), path_or_fileobj=str(file_path) ) ) # 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}" print(f"[PR] Prepared {len(operations)} file operations") commit_info = api.upload_folder( folder_path=str(temp_path), # Create commit with PR commit_info = api.create_commit( 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 branch operations=operations, commit_message=pr_title, commit_description=pr_description, create_pr=True, # This creates a PR with the changes token=token ) success_msg = f"✅ Pull Request created! View at: {discussion.url}" print(f"[PR] {success_msg}") # Extract PR URL pr_url = commit_info.pr_url if hasattr(commit_info, 'pr_url') else None pr_num = commit_info.pr_num if hasattr(commit_info, 'pr_num') else None if not pr_url and pr_num: pr_url = f"https://huggingface.co/spaces/{repo_id}/discussions/{pr_num}" elif not pr_url: pr_url = f"https://huggingface.co/spaces/{repo_id}/discussions" print(f"[PR] Created PR: {pr_url}") success_msg = f"✅ Pull Request created! View at: {pr_url}" return True, success_msg, discussion.url return True, success_msg, pr_url except Exception as e: print(f"[PR] Error creating pull request: {e}")backend_deploy.py+34-24