Spaces:
Sleeping
Sleeping
Fix: Use GitHub REST API directly to enable Pages
Browse files- student/github_manager.py +24 -11
student/github_manager.py
CHANGED
|
@@ -274,24 +274,37 @@ SOFTWARE.
|
|
| 274 |
Returns:
|
| 275 |
Pages URL
|
| 276 |
"""
|
| 277 |
-
|
| 278 |
-
repo = self.user.get_repo(repo_name)
|
| 279 |
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
logger.info(f"Enabled GitHub Pages for {repo_name}")
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
raise
|
| 289 |
|
| 290 |
# Construct Pages URL
|
| 291 |
pages_url = f"https://{settings.github_username}.github.io/{repo_name}/"
|
| 292 |
return pages_url
|
| 293 |
|
| 294 |
-
except
|
| 295 |
logger.error(f"Failed to enable Pages for {repo_name}: {e}")
|
| 296 |
# Return expected URL even if enabling fails
|
| 297 |
return f"https://{settings.github_username}.github.io/{repo_name}/"
|
|
|
|
| 274 |
Returns:
|
| 275 |
Pages URL
|
| 276 |
"""
|
| 277 |
+
import requests
|
|
|
|
| 278 |
|
| 279 |
+
try:
|
| 280 |
+
# Use GitHub REST API to enable Pages
|
| 281 |
+
api_url = f"https://api.github.com/repos/{settings.github_username}/{repo_name}/pages"
|
| 282 |
+
headers = {
|
| 283 |
+
"Accept": "application/vnd.github+json",
|
| 284 |
+
"Authorization": f"Bearer {settings.github_token}",
|
| 285 |
+
"X-GitHub-Api-Version": "2022-11-28"
|
| 286 |
+
}
|
| 287 |
+
data = {
|
| 288 |
+
"source": {
|
| 289 |
+
"branch": "main",
|
| 290 |
+
"path": "/"
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
response = requests.post(api_url, headers=headers, json=data)
|
| 295 |
+
|
| 296 |
+
if response.status_code == 201:
|
| 297 |
logger.info(f"Enabled GitHub Pages for {repo_name}")
|
| 298 |
+
elif response.status_code == 409:
|
| 299 |
+
logger.info(f"GitHub Pages already enabled for {repo_name}")
|
| 300 |
+
else:
|
| 301 |
+
logger.warning(f"Pages enable response: {response.status_code} - {response.text}")
|
|
|
|
| 302 |
|
| 303 |
# Construct Pages URL
|
| 304 |
pages_url = f"https://{settings.github_username}.github.io/{repo_name}/"
|
| 305 |
return pages_url
|
| 306 |
|
| 307 |
+
except Exception as e:
|
| 308 |
logger.error(f"Failed to enable Pages for {repo_name}: {e}")
|
| 309 |
# Return expected URL even if enabling fails
|
| 310 |
return f"https://{settings.github_username}.github.io/{repo_name}/"
|