akhaliq HF Staff commited on
Commit
04e1fb9
Β·
1 Parent(s): 2f7e3a4
backend_deploy.py CHANGED
@@ -1317,6 +1317,18 @@ def create_pull_request_on_space(
1317
  try:
1318
  api = HfApi(token=token)
1319
 
 
 
 
 
 
 
 
 
 
 
 
 
1320
  # Default PR title and description
1321
  if not pr_title:
1322
  pr_title = "🎨 Redesign from AnyCoder"
@@ -1420,7 +1432,7 @@ Generated by [AnyCoder](https://huggingface.co/spaces/akhaliq/anycoder)"""
1420
 
1421
  print(f"[PR] Prepared {len(operations)} file operations")
1422
 
1423
- # Create commit with PR
1424
  commit_info = api.create_commit(
1425
  repo_id=repo_id,
1426
  repo_type="space",
@@ -1428,7 +1440,6 @@ Generated by [AnyCoder](https://huggingface.co/spaces/akhaliq/anycoder)"""
1428
  commit_message=pr_title,
1429
  commit_description=pr_description,
1430
  create_pr=True, # This creates a PR with the changes
1431
- token=token
1432
  )
1433
 
1434
  # Extract PR URL
@@ -1446,10 +1457,30 @@ Generated by [AnyCoder](https://huggingface.co/spaces/akhaliq/anycoder)"""
1446
  return True, success_msg, pr_url
1447
 
1448
  except Exception as e:
1449
- print(f"[PR] Error creating pull request: {e}")
 
1450
  import traceback
1451
  traceback.print_exc()
1452
- return False, f"Failed to create pull request: {str(e)}", None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1453
 
1454
  except Exception as e:
1455
  print(f"[PR] Top-level exception: {type(e).__name__}: {str(e)}")
 
1317
  try:
1318
  api = HfApi(token=token)
1319
 
1320
+ # Check if we can access the space first
1321
+ try:
1322
+ space_info = api.space_info(repo_id=repo_id, token=token)
1323
+ print(f"[PR] Space info: private={space_info.private if hasattr(space_info, 'private') else 'unknown'}")
1324
+
1325
+ # Check if space is private
1326
+ if hasattr(space_info, 'private') and space_info.private:
1327
+ return False, "❌ Cannot create PR on private space. The space must be public to accept PRs from others.", None
1328
+ except Exception as info_error:
1329
+ print(f"[PR] Could not fetch space info: {info_error}")
1330
+ # Continue anyway - maybe we can still create the PR
1331
+
1332
  # Default PR title and description
1333
  if not pr_title:
1334
  pr_title = "🎨 Redesign from AnyCoder"
 
1432
 
1433
  print(f"[PR] Prepared {len(operations)} file operations")
1434
 
1435
+ # Create commit with PR (token already in HfApi instance)
1436
  commit_info = api.create_commit(
1437
  repo_id=repo_id,
1438
  repo_type="space",
 
1440
  commit_message=pr_title,
1441
  commit_description=pr_description,
1442
  create_pr=True, # This creates a PR with the changes
 
1443
  )
1444
 
1445
  # Extract PR URL
 
1457
  return True, success_msg, pr_url
1458
 
1459
  except Exception as e:
1460
+ error_msg = str(e)
1461
+ print(f"[PR] Error creating pull request: {error_msg}")
1462
  import traceback
1463
  traceback.print_exc()
1464
+
1465
+ # Provide helpful error message based on the error type
1466
+ if "403" in error_msg or "Forbidden" in error_msg or "Authorization" in error_msg:
1467
+ user_msg = (
1468
+ "❌ Cannot create Pull Request: Permission denied.\n\n"
1469
+ "**Possible reasons:**\n"
1470
+ "- The space owner hasn't enabled Pull Requests\n"
1471
+ "- You don't have write access to this space\n"
1472
+ "- Spaces have stricter PR permissions than models/datasets\n\n"
1473
+ "**What you can do:**\n"
1474
+ "βœ… Use the 'Redesign' button WITHOUT checking 'Create PR' - this will:\n"
1475
+ " 1. Duplicate the space to your account\n"
1476
+ " 2. Apply the redesign to your copy\n"
1477
+ " 3. You'll own the new space!\n\n"
1478
+ "Or contact the space owner to enable Pull Requests."
1479
+ )
1480
+ else:
1481
+ user_msg = f"Failed to create pull request: {error_msg}"
1482
+
1483
+ return False, user_msg, None
1484
 
1485
  except Exception as e:
1486
  print(f"[PR] Top-level exception: {type(e).__name__}: {str(e)}")
frontend/src/components/LandingPage.tsx CHANGED
@@ -807,7 +807,7 @@ Note: After generating the redesign, I will create a Pull Request on the origina
807
  />
808
 
809
  {/* PR Option */}
810
- <label className="flex items-center gap-2 mb-3 cursor-pointer">
811
  <input
812
  type="checkbox"
813
  checked={createPR}
@@ -820,6 +820,12 @@ Note: After generating the redesign, I will create a Pull Request on the origina
820
  </span>
821
  </label>
822
 
 
 
 
 
 
 
823
  {redesignError && (
824
  <p className="text-xs text-red-400 mb-2">{redesignError}</p>
825
  )}
 
807
  />
808
 
809
  {/* PR Option */}
810
+ <label className="flex items-center gap-2 mb-1 cursor-pointer">
811
  <input
812
  type="checkbox"
813
  checked={createPR}
 
820
  </span>
821
  </label>
822
 
823
+ {createPR && (
824
+ <p className="text-[10px] text-[#86868b] mb-2 ml-6">
825
+ ⚠️ Note: PR creation requires space owner to enable PRs. If disabled, uncheck this to duplicate the space instead.
826
+ </p>
827
+ )}
828
+
829
  {redesignError && (
830
  <p className="text-xs text-red-400 mb-2">{redesignError}</p>
831
  )}