akhaliq HF Staff commited on
Commit
a21948d
·
1 Parent(s): e19eb49
Files changed (2) hide show
  1. backend_deploy.py +3 -4
  2. frontend/src/app/page.tsx +3 -3
backend_deploy.py CHANGED
@@ -1400,18 +1400,17 @@ Generated by [AnyCoder](https://huggingface.co/spaces/akhaliq/anycoder)"""
1400
  file_path.write_text(content, encoding='utf-8')
1401
 
1402
  # Create PR using the correct API flow:
1403
- # 1. Create discussion with pull_request=True
1404
  # 2. Add commits to the PR branch
1405
  try:
1406
  print(f"[PR] Creating pull request on {repo_id}")
1407
 
1408
- # Step 1: Create the PR (draft mode)
1409
- discussion = api.create_discussion(
1410
  repo_id=repo_id,
1411
  title=pr_title,
1412
  description=pr_description,
1413
  repo_type="space",
1414
- pull_request=True, # This makes it a PR instead of discussion
1415
  token=token
1416
  )
1417
 
 
1400
  file_path.write_text(content, encoding='utf-8')
1401
 
1402
  # Create PR using the correct API flow:
1403
+ # 1. Create PR with create_pull_request()
1404
  # 2. Add commits to the PR branch
1405
  try:
1406
  print(f"[PR] Creating pull request on {repo_id}")
1407
 
1408
+ # Step 1: Create the PR (draft mode) using the wrapper function
1409
+ discussion = api.create_pull_request(
1410
  repo_id=repo_id,
1411
  title=pr_title,
1412
  description=pr_description,
1413
  repo_type="space",
 
1414
  token=token
1415
  )
1416
 
frontend/src/app/page.tsx CHANGED
@@ -238,7 +238,7 @@ export default function Home() {
238
  }
239
  };
240
 
241
- const handleSendMessage = async (message: string, overrideLanguage?: Language, overrideModel?: string, overrideRepoId?: string) => {
242
  if (!isAuthenticated) {
243
  alert('Please sign in with HuggingFace first! Click the "Sign in with Hugging Face" button in the header.');
244
  return;
@@ -301,7 +301,7 @@ export default function Home() {
301
  history: messages.map((m) => [m.role, m.content]),
302
  agent_mode: false,
303
  existing_repo_id: effectiveRepoId, // Pass duplicated/imported space ID for auto-deploy
304
- skip_auto_deploy: !!pendingPR, // Skip auto-deploy if PR is pending
305
  };
306
 
307
  const assistantMessage: Message = {
@@ -789,7 +789,7 @@ export default function Home() {
789
 
790
  // Send the message with the selected language and model
791
  // Don't pass repoId to handleSendMessage when creating PR (we want to generate code first, then create PR)
792
- await handleSendMessage(prompt, language, modelId, shouldCreatePR ? undefined : repoId);
793
  };
794
 
795
  // Resize handlers for chat sidebar (desktop only)
 
238
  }
239
  };
240
 
241
+ const handleSendMessage = async (message: string, overrideLanguage?: Language, overrideModel?: string, overrideRepoId?: string, shouldCreatePR?: boolean) => {
242
  if (!isAuthenticated) {
243
  alert('Please sign in with HuggingFace first! Click the "Sign in with Hugging Face" button in the header.');
244
  return;
 
301
  history: messages.map((m) => [m.role, m.content]),
302
  agent_mode: false,
303
  existing_repo_id: effectiveRepoId, // Pass duplicated/imported space ID for auto-deploy
304
+ skip_auto_deploy: !!shouldCreatePR, // Skip auto-deploy if creating PR
305
  };
306
 
307
  const assistantMessage: Message = {
 
789
 
790
  // Send the message with the selected language and model
791
  // Don't pass repoId to handleSendMessage when creating PR (we want to generate code first, then create PR)
792
+ await handleSendMessage(prompt, language, modelId, shouldCreatePR ? undefined : repoId, shouldCreatePR);
793
  };
794
 
795
  // Resize handlers for chat sidebar (desktop only)