-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_webhook_local.py
More file actions
94 lines (77 loc) · 2.63 KB
/
Copy pathtest_webhook_local.py
File metadata and controls
94 lines (77 loc) · 2.63 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
89
90
91
92
93
import os
import sys
# Ensure API keys are loaded
if "GEMINI_API_KEY" not in os.environ:
print("WARNING: GEMINI_API_KEY not set")
if "GITHUB_TOKEN" not in os.environ:
print("WARNING: GITHUB_TOKEN not set")
# 1. Modify the mock event to match the user's screenshot
payload = {
"action": "created",
"repository": {
"full_name": "HOLYKEYZ/joe-gemini"
},
"issue": {
"number": 2,
"title": "Missing CI/CD Strategy for Monorepo #2"
},
"comment": {
"id": 123456789,
"body": "mayo, try this time, it should work...",
"user": {
"login": "HOLYKEYZ",
"type": "User"
}
},
"installation": {
"id": 1234 # Fake ID, will patch get_github_client
}
}
import api.index as bot
from unittest.mock import MagicMock
# Create a full mock of the Github client
mock_gh = MagicMock()
mock_repo = MagicMock()
mock_gh.get_repo.return_value = mock_repo
mock_issue = MagicMock()
mock_issue.title = "Test Issue"
mock_issue.body = "Test body"
mock_issue.pull_request = False
mock_repo.get_issue.return_value = mock_issue
# Mock the comments list to simulate the user's comment
mock_prev_comment = MagicMock()
mock_prev_comment.id = 111
mock_prev_comment.user.login = "joe-gemini-bot[bot]"
mock_prev_comment.body = "Previous bot comment here"
mock_current_comment = MagicMock()
mock_current_comment.id = 123456789
mock_current_comment.user.login = "HOLYKEYZ"
mock_current_comment.body = "mayo, try this time, it should work..."
mock_issue.get_comments.return_value = [mock_prev_comment, mock_current_comment]
# Mock fetch_memory
bot.fetch_memory = MagicMock(return_value={"files_read": []})
bot.get_repo_structure = MagicMock(return_value="fake structure")
bot.get_context_expansion_files = MagicMock(return_value=[])
bot.get_bot_login = MagicMock(return_value="joe-gemini-bot[bot]")
def fake_get_github_client(install_id):
return mock_gh
bot.get_github_client = fake_get_github_client
# Patch index.py prints to easily see where we are
original_handle = bot.handle_issue_comment
def trace_calls(frame, event, arg):
if frame.f_code.co_name == 'handle_issue_comment':
if event == 'line':
print(f"Executing line {frame.f_lineno} in handle_issue_comment")
elif event == 'return':
print(f"<-- Returning from handle_issue_comment")
return trace_calls
try:
print("Testing handle_issue_comment locally with Mocks...")
sys.settrace(trace_calls)
original_handle(payload)
sys.settrace(None)
print("Finished successfully")
except Exception as e:
import traceback
print("CRASHED:")
traceback.print_exc()