-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
97 lines (78 loc) · 2.7 KB
/
main.py
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
94
95
96
97
import os
from agent import get_graph
from inputs import from_github
from langchain_core.messages import HumanMessage
from tools import get_pr_metadata
import traceback
from composio import Action, ComposioToolSet
from composio.utils.logging import get_logger
listener = ComposioToolSet().create_trigger_listener()
logger = get_logger(__name__)
# Triggers when a new event takes place
@listener.callback(filters={"trigger_name": "GITHUB_PULL_REQUEST_EVENT"})
def callback_function(event):
try:
logger.info("Received trigger GITHUB_PULL_REQUEST_EVENT")
payload = event.payload
action = payload.get("action")
if action not in ["opened", "reopened"]:
return
url = payload.get("url")
split_url = url.split("/")
owner = split_url[-4]
repo_name = split_url[-3]
pull_number = payload.get("number")
logger.info(f"Running PR Review agent for pull request {url}")
run_agent(owner, repo_name, pull_number)
except Exception as e:
traceback.print_exc()
def run_agent(owner, repo_name, pull_number) -> None:
repo_path = f"/home/user/{repo_name}"
graph, composio_toolset = get_graph(repo_path)
composio_toolset.execute_action(
action=Action.FILETOOL_CHANGE_WORKING_DIRECTORY,
params={"path": "/home/user/"},
)
composio_toolset.execute_action(
action=Action.FILETOOL_GIT_CLONE,
params={"repo_name": f"{owner}/{repo_name}"},
)
composio_toolset.execute_action(
action=Action.FILETOOL_CHANGE_WORKING_DIRECTORY,
params={"path": repo_path},
)
response = composio_toolset.execute_action(
action=get_pr_metadata,
params={
"owner": owner,
"repo": repo_name,
"pull_number": str(pull_number),
"thought": "Get the metadata for the PR",
},
)
base_commit = response["data"]["metadata"]["base"]["sha"]
composio_toolset.execute_action(
action=Action.FILETOOL_GIT_CLONE,
params={
"repo_name": f"{owner}/{repo_name}",
"just_reset": True,
"commit_id": base_commit,
},
)
composio_toolset.execute_action(
action=Action.CODE_ANALYSIS_TOOL_CREATE_CODE_MAP,
params={},
)
run_result = graph.invoke(
{
"messages": [
HumanMessage(
content=f"You have {owner}/{repo_name} cloned at your current working directory. Review PR {pull_number} on this repository and create comments on the same PR"
)
]
},
{"recursion_limit": 70},
)
print(run_result)
if __name__ == "__main__":
listener.wait_forever()