CheeksTheGeek commited on
Commit
5613139
·
unverified ·
1 Parent(s): e16482d

Fix: Use GitHub REST API directly to enable Pages

Browse files
Files changed (1) hide show
  1. student/github_manager.py +24 -11
student/github_manager.py CHANGED
@@ -274,24 +274,37 @@ SOFTWARE.
274
  Returns:
275
  Pages URL
276
  """
277
- try:
278
- repo = self.user.get_repo(repo_name)
279
 
280
- # Enable Pages on main branch
281
- try:
282
- repo.create_pages_site(source={"branch": "main", "path": "/"})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  logger.info(f"Enabled GitHub Pages for {repo_name}")
284
- except GithubException as e:
285
- if "already enabled" in str(e).lower():
286
- logger.info(f"GitHub Pages already enabled for {repo_name}")
287
- else:
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 GithubException as e:
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}/"