forked from AOSSIE-Org/Devr.AI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepository_query.py
More file actions
46 lines (38 loc) · 1.5 KB
/
repository_query.py
File metadata and controls
46 lines (38 loc) · 1.5 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
from ..services.github_mcp_client import GitHubMCPClient
import re
#GitHub URL forms: https(s)://github.com/owner/repo[.git][...], git@github.com:owner/repo[.git]
GH_URL_RE = re.compile(
r'(?:https?://|git@)github\.com[/:]'
r'([A-Za-z0-9](?:-?[A-Za-z0-9]){0,38})/'
r'([A-Za-z0-9._-]+?)(?:\.git)?(?:/|$)',
re.IGNORECASE,
)
OWNER_REPO_RE = re.compile(
r'\b([A-Za-z0-9](?:-?[A-Za-z0-9]){0,38})/([A-Za-z0-9._-]{1,100})\b'
)
async def handle_repo_query(user_query: str) -> dict:
m = GH_URL_RE.search(user_query) or OWNER_REPO_RE.search(user_query)
if not m:
return {"status": "error", "message": "Usage: include a GitHub owner/repo (e.g., AOSSIE-Org/Devr.AI) or a GitHub URL."}
owner, repo = m.group(1), m.group(2)
# Use the GitHub MCP client to communicate with the MCP server
async with GitHubMCPClient() as client:
if not await client.is_server_available():
return {
"status": "error",
"message": "GitHub MCP server not available. Please ensure the MCP server is running."
}
result = await client.get_repo_info(owner, repo)
if "error" in result:
return {
"status": "error",
"owner": owner,
"repo": repo,
"message": result["error"]
}
return {
"status": "success",
"owner": owner,
"repo": repo,
"data": result
}