forked from ansible-network/Ansieyes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bot.py
More file actions
89 lines (76 loc) · 2.3 KB
/
Copy pathtest_bot.py
File metadata and controls
89 lines (76 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
"""
Test script for the GitHub PR Review Bot
"""
import os
import sys
from dotenv import load_dotenv
from pr_reviewer import PRReviewer
load_dotenv()
def test_gemini_connection():
"""Test Gemini API connection"""
api_key = os.getenv('GEMINI_API_KEY')
if not api_key:
print("❌ GEMINI_API_KEY not set in .env file")
return False
print("Testing Gemini API connection...")
reviewer = PRReviewer(api_key)
# Test with a simple prompt
try:
test_prompt = "Say 'Hello, GitHub Bot!' if you can read this."
response = reviewer.model.generate_content(test_prompt)
print(f"✅ Gemini API connection successful!")
print(f"Response: {response.text[:100]}")
return True
except Exception as e:
print(f"❌ Gemini API connection failed: {e}")
return False
def test_pr_review():
"""Test PR review functionality"""
api_key = os.getenv('GEMINI_API_KEY')
if not api_key:
print("❌ GEMINI_API_KEY not set")
return False
reviewer = PRReviewer(api_key)
# Mock PR data
title = "Add user authentication"
body = "This PR adds user authentication functionality"
file_changes = [
{
'filename': 'auth.py',
'status': 'added',
'additions': 50,
'deletions': 0,
'patch': '''
+def login(username, password):
+ if username == "admin" and password == "password":
+ return True
+ return False
'''
}
]
print("\nTesting PR review generation...")
try:
review = reviewer.review_pr(title, body, file_changes)
if review:
print("✅ PR review generated successfully!")
print("\nReview Summary:")
print(review.get('summary', '')[:500])
return True
else:
print("❌ Empty review returned")
return False
except Exception as e:
print(f"❌ PR review failed: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == '__main__':
print("🧪 Testing GitHub PR Review Bot\n")
# Test Gemini connection
if not test_gemini_connection():
sys.exit(1)
# Test PR review
if not test_pr_review():
sys.exit(1)
print("\n✅ All tests passed!")