-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_github_composio.py
More file actions
266 lines (222 loc) · 9.8 KB
/
Copy pathtest_github_composio.py
File metadata and controls
266 lines (222 loc) · 9.8 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from composio_openai import ComposioToolSet, Action
from openai import OpenAI
import json
import os
# Initialize
openai_client = OpenAI(api_key="")
composio_toolset = ComposioToolSet(entity_id="default")
# ======== ISSUES LIST TEST ========>
# Get the specific action we want to test
# tools = composio_toolset.get_tools(actions=[Action.GITHUB_ISSUES_LIST_FOR_REPO])
# task = "Fetch the first 3 open issues from vercel/next-learn repository on GitHub"
# print("🔍 Testing GITHUB_ISSUES_LIST_FOR_REPO...")
# print(f"Task: {task}")
# print("-" * 50)
# response = openai_client.chat.completions.create(
# model="gpt-4o",
# tools=tools,
# messages=[
# {
# "role": "system",
# "content": "You are a helpful assistant that can fetch GitHub issues.",
# },
# {"role": "user", "content": task},
# ],
# )
# result = composio_toolset.handle_tool_calls(response)
# print("📋 Full Results (No Truncation):")
# print("-" * 50)
# for item in result:
# if item.get("successful"):
# print("✅ Success!")
# # Print FULL raw data structure (no truncation)
# print("\n🔧 Complete Raw Data Structure:")
# print(json.dumps(item["data"], indent=2))
# # Try to extract and display key information
# try:
# # Handle both possible data structures
# if "details" in item["data"]:
# issues_data = item["data"]["details"]
# print(
# f"\n📊 Data structure: item['data']['details'] with {len(issues_data)} issues"
# )
# else:
# issues_data = item["data"]
# print(
# f"\n📊 Data structure: item['data'] directly with {len(issues_data)} issues"
# )
# if isinstance(issues_data, list):
# # Show ALL issues, not just first 3
# for i, issue in enumerate(issues_data):
# print(f"\n--- Issue {i+1} ---")
# print(f"Title: {issue.get('title', 'N/A')}")
# print(f"Number: #{issue.get('number', 'N/A')}")
# print(f"State: {issue.get('state', 'N/A')}")
# print(
# f"Labels: {[label.get('name') for label in issue.get('labels', [])]}"
# )
# print(
# f"Assignees: {[assignee.get('login') for assignee in issue.get('assignees', [])]}"
# )
# print(f"Created: {issue.get('created_at', 'N/A')}")
# else:
# print(f"⚠️ Issues data is not a list, it's: {type(issues_data)}")
# print(f"Content: {issues_data}")
# except Exception as e:
# print(f"Error parsing issues: {e}")
# print(f"Raw item data type: {type(item['data'])}")
# print(f"Raw item data: {item['data']}")
# else:
# print("❌ Failed!")
# print(f"Error: {item.get('error', 'Unknown error')}")
# <============ END OF ISSUES LIST TEST ========>
# ======== GET PRs ========>
# tools = composio_toolset.get_tools(actions=[Action.GITHUB_LIST_PULL_REQUESTS])
# # Test with explicit count to avoid per_page=1 default
# task = "Get the 2 newest open pull requests from vercel/next-learn repository, sorted by most recently created first"
# print("🔍 Testing GITHUB_LIST_PULL_REQUESTS...")
# print(f"Task: {task}")
# print("-" * 50)
# response = openai_client.chat.completions.create(
# model="gpt-4o",
# tools=tools,
# messages=[
# {
# "role": "system",
# "content": "You are a helpful assistant. When fetching GitHub pull requests, try to get multiple PRs, not just one.",
# },
# {"role": "user", "content": task},
# ],
# )
# # Execute the action
# result = composio_toolset.handle_tool_calls(response)
# print("📋 Full Results (No Truncation):")
# print("-" * 50)
# for item in result:
# if item.get("successful"):
# print("✅ Success!")
# # Print FULL raw data structure (no truncation)
# print("\n🔧 Complete Raw Data Structure:")
# print(json.dumps(item["data"], indent=2))
# # Try to extract and display key information
# try:
# # Handle both possible data structures
# if "details" in item["data"]:
# prs_data = item["data"]["details"]
# print(
# f"\n📊 Data structure: item['data']['details'] with {len(prs_data)} PRs"
# )
# else:
# prs_data = item["data"]
# print(
# f"\n📊 Data structure: item['data'] directly with {len(prs_data)} PRs"
# )
# if isinstance(prs_data, list):
# # Show ALL PRs
# for i, pr in enumerate(prs_data):
# print(f"\n--- PR {i+1} ---")
# print(f"Title: {pr.get('title', 'N/A')}")
# print(f"Number: #{pr.get('number', 'N/A')}")
# print(f"State: {pr.get('state', 'N/A')}")
# print(f"Author: {pr.get('user', {}).get('login', 'N/A')}")
# print(
# f"Labels: {[label.get('name') for label in pr.get('labels', [])]}"
# )
# # Check for assignees (key for your workflow)
# print(
# f"Assignees: {[assignee.get('login') for assignee in pr.get('assignees', [])]}"
# )
# # Check for reviewers (key for your workflow)
# requested_reviewers = pr.get("requested_reviewers", [])
# print(
# f"Requested Reviewers: {[reviewer.get('login') for reviewer in requested_reviewers]}"
# )
# print(f"Created: {pr.get('created_at', 'N/A')}")
# print(f"Draft: {pr.get('draft', 'N/A')}")
# else:
# print(f"⚠️ PRs data is not a list, it's: {type(prs_data)}")
# print(f"Content: {prs_data}")
# except Exception as e:
# print(f"Error parsing PRs: {e}")
# print(f"Raw item data type: {type(item['data'])}")
# print(f"Raw item data: {item['data']}")
# else:
# print("❌ Failed!")
# print(f"Error: {item.get('error', 'Unknown error')}")
# print("\n" + "=" * 50)
# print("🎯 This PR data will be used for:")
# print("- Creating Notion pages with PR info")
# print("- Detecting 'bug' labels on PRs")
# print("- Finding assignees + reviewers for meeting scheduling")
# ======== END OF GETTING PRs ========>
# ============> GETTING COLLABORATORS <===========
# Get the repository collaborators action
tools = composio_toolset.get_tools(
actions=[Action.GITHUB_LIST_REPOSITORY_COLLABORATORS]
)
# Test with the same repo we've been using
task = "List all collaborators for the Taofiqq/crewai-composio-mcp-server repository"
print("🔍 Testing GITHUB_LIST_REPOSITORY_COLLABORATORS...")
print(f"Task: {task}")
print("-" * 50)
response = openai_client.chat.completions.create(
model="gpt-4o",
tools=tools,
messages=[
{
"role": "system",
"content": "You are a helpful assistant that can fetch GitHub repository collaborators.",
},
{"role": "user", "content": task},
],
)
# Execute the action
result = composio_toolset.handle_tool_calls(response)
print("📋 Full Results (No Truncation):")
print("-" * 50)
for item in result:
if item.get("successful"):
print("✅ Success!")
# Print FULL raw data structure (no truncation)
print("\n🔧 Complete Raw Data Structure:")
print(json.dumps(item["data"], indent=2))
# Try to extract and display key information
try:
# Handle both possible data structures
if "details" in item["data"]:
collaborators_data = item["data"]["details"]
print(
f"\n📊 Data structure: item['data']['details'] with {len(collaborators_data)} collaborators"
)
else:
collaborators_data = item["data"]
print(
f"\n📊 Data structure: item['data'] directly with {len(collaborators_data)} collaborators"
)
if isinstance(collaborators_data, list):
# Show ALL collaborators
for i, collaborator in enumerate(collaborators_data):
print(f"\n--- Collaborator {i+1} ---")
print(f"Username: {collaborator.get('login', 'N/A')}")
print(f"Name: {collaborator.get('name', 'N/A')}")
print(f"Email: {collaborator.get('email', 'N/A')}")
print(f"Role/Permissions: {collaborator.get('permissions', 'N/A')}")
print(f"Type: {collaborator.get('type', 'N/A')}")
print(f"Site Admin: {collaborator.get('site_admin', 'N/A')}")
else:
print(
f"⚠️ Collaborators data is not a list, it's: {type(collaborators_data)}"
)
print(f"Content: {collaborators_data}")
except Exception as e:
print(f"Error parsing collaborators: {e}")
print(f"Raw item data type: {type(item['data'])}")
print(f"Raw item data: {item['data']}")
else:
print("❌ Failed!")
print(f"Error: {item.get('error', 'Unknown error')}")
print("\n" + "=" * 50)
print("🎯 This collaborator data will be used for:")
print("- Identifying repository maintainers")
print("- Adding maintainers to meeting invitations when bugs are found")
print("- Understanding who has write access to the repository")