JirasakJo commited on
Commit
ae0a1d9
Β·
verified Β·
1 Parent(s): 943f998

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -31
app.py CHANGED
@@ -332,59 +332,90 @@ def display_chat_history():
332
 
333
  def initialize_github_sync():
334
  """
335
- Initialize GitHub repository connection with authentication handling.
336
  """
337
  try:
338
- repo_path = Path(os.getenv('GITHUB_REPO_PATH', '')).resolve()
 
339
  print(f"Initializing repo at: {repo_path}")
340
 
 
341
  if not repo_path.exists():
342
- print(f"Repository directory not found: {repo_path}")
343
  return False
344
 
345
  try:
 
346
  repo = Repo(str(repo_path))
347
 
 
348
  if not (repo_path / '.git').exists():
349
  print(".git directory not found")
350
  return False
351
 
 
352
  try:
353
  origin = repo.remote('origin')
354
  urls = list(origin.urls)
355
  if not urls:
356
  print("Remote 'origin' has no URL")
357
  return False
358
-
359
- if GITHUB_REPO_URL not in urls:
360
- print(f"Unexpected remote URL: {urls[0]}")
361
- return False
362
-
363
- print(f"Verified remote URL: {urls[0]}")
364
 
365
  # Test Git operations
366
  try:
367
- repo.git.status()
368
- print("Git status check passed")
 
369
  return True
370
 
371
- except git.GitCommandError as auth_error:
372
- if "Authentication failed" in str(auth_error):
373
- print("Authentication failed - please check your Git credentials")
374
  return False
375
 
376
- except ValueError:
377
- print("Remote 'origin' not configured")
378
  return False
379
 
380
  except Exception as repo_error:
381
- print(f"Repository validation failed: {str(repo_error)}")
382
  return False
383
 
384
  except Exception as e:
385
- print(f"Initialization failed: {str(e)}")
386
  return False
387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
  def debug_github_connection():
389
  """
390
  Debug GitHub connection issues and print detailed status
@@ -597,19 +628,37 @@ def main():
597
  save_qa_history([]) # Clear saved history
598
  st.rerun()
599
 
600
- with st.expander("πŸ”§ Debug GitHub Connection"):
601
- if st.button("Test GitHub Connection"):
602
- with st.spinner("Testing GitHub connection..."):
603
- repo_path = os.getenv('GITHUB_REPO_PATH')
604
- st.write(f"Current repository path: {repo_path}")
605
- st.write(f"Path exists: {os.path.exists(repo_path)}")
606
- st.write(f"Git directory exists: {os.path.exists(os.path.join(repo_path, '.git'))}")
607
-
608
- debug_result = debug_github_connection()
609
- if debug_result:
610
- st.success("βœ… GitHub connection test passed!")
611
- else:
612
- st.error("❌ GitHub connection test failed. Check the logs below.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
613
 
614
  with info_col:
615
  # System information
 
332
 
333
  def initialize_github_sync():
334
  """
335
+ Initialize GitHub repository connection with proper path verification
336
  """
337
  try:
338
+ # Use the exact path where we know the repository exists
339
+ repo_path = Path(r"D:\Last SWU\swu-chat-bot-project")
340
  print(f"Initializing repo at: {repo_path}")
341
 
342
+ # Verify repository exists
343
  if not repo_path.exists():
344
+ print(f"Repository directory not found at: {repo_path}")
345
  return False
346
 
347
  try:
348
+ # Initialize repository
349
  repo = Repo(str(repo_path))
350
 
351
+ # Verify .git directory
352
  if not (repo_path / '.git').exists():
353
  print(".git directory not found")
354
  return False
355
 
356
+ # Check remote configuration
357
  try:
358
  origin = repo.remote('origin')
359
  urls = list(origin.urls)
360
  if not urls:
361
  print("Remote 'origin' has no URL")
362
  return False
363
+
364
+ print(f"Connected to remote: {urls[0]}")
 
 
 
 
365
 
366
  # Test Git operations
367
  try:
368
+ status = repo.git.status()
369
+ print("Git status verified:")
370
+ print(status)
371
  return True
372
 
373
+ except git.GitCommandError as git_error:
374
+ print(f"Git command error: {str(git_error)}")
 
375
  return False
376
 
377
+ except ValueError as remote_error:
378
+ print(f"Remote error: {str(remote_error)}")
379
  return False
380
 
381
  except Exception as repo_error:
382
+ print(f"Repository error: {str(repo_error)}")
383
  return False
384
 
385
  except Exception as e:
386
+ print(f"Initialization error: {str(e)}")
387
  return False
388
 
389
+ # Add this function to test the connection
390
+ def test_github_connection():
391
+ """
392
+ Test GitHub connection by attempting a simple operation
393
+ """
394
+ try:
395
+ repo_path = Path(r"D:\Last SWU\swu-chat-bot-project")
396
+ repo = Repo(str(repo_path))
397
+
398
+ # Get current status
399
+ status = repo.git.status()
400
+ print("Repository Status:")
401
+ print(status)
402
+
403
+ # Get remote information
404
+ origin = repo.remote('origin')
405
+ print("\nRemote URLs:")
406
+ for url in origin.urls:
407
+ print(url)
408
+
409
+ # Get current branch
410
+ branch = repo.active_branch
411
+ print(f"\nActive branch: {branch.name}")
412
+
413
+ return True
414
+
415
+ except Exception as e:
416
+ print(f"Connection test failed: {str(e)}")
417
+ return False
418
+
419
  def debug_github_connection():
420
  """
421
  Debug GitHub connection issues and print detailed status
 
628
  save_qa_history([]) # Clear saved history
629
  st.rerun()
630
 
631
+ # Add this to your main() function in the info_col section
632
+ with st.expander("πŸ”§ GitHub Connection Status", expanded=True):
633
+ col1, col2 = st.columns([1, 2])
634
+
635
+ with col1:
636
+ if st.button("Test Connection"):
637
+ with st.spinner("Testing connection..."):
638
+ if test_github_connection():
639
+ st.success("βœ… GitHub connection successful!")
640
+ st.session_state.github_sync_enabled = True
641
+ else:
642
+ st.error("❌ GitHub connection failed!")
643
+ st.session_state.github_sync_enabled = False
644
+
645
+ with col2:
646
+ # Display current status
647
+ status = "🟒 Connected" if st.session_state.github_sync_enabled else "πŸ”΄ Disconnected"
648
+ st.info(f"Current Status: {status}")
649
+
650
+ # Show repository details
651
+ if st.checkbox("Show Repository Details"):
652
+ repo_path = Path(r"D:\Last SWU\swu-chat-bot-project")
653
+ repo = Repo(str(repo_path))
654
+
655
+ st.write("Repository Information:")
656
+ st.code(f"""
657
+ Path: {repo_path}
658
+ Remote URL: {list(repo.remote('origin').urls)[0]}
659
+ Current Branch: {repo.active_branch.name}
660
+ Git Status: {repo.git.status()}
661
+ """)
662
 
663
  with info_col:
664
  # System information