HimanshuGoyal2004 commited on
Commit
f8c7c4a
·
1 Parent(s): c9a56ff
Files changed (1) hide show
  1. app.py +13 -65
app.py CHANGED
@@ -58,8 +58,8 @@ class GitHubMCPServer:
58
  "error": f"Failed to fetch repository information: {str(e)}"
59
  }
60
 
61
- def get_file_content(self, owner: str, repo: str, path: str) -> dict:
62
- """Get content of a specific file"""
63
  try:
64
  url = f"https://api.github.com/repos/{owner}/{repo}/contents/{path}"
65
  response = requests.get(url, headers=self.headers)
@@ -70,82 +70,30 @@ class GitHubMCPServer:
70
  # Decode base64 content
71
  try:
72
  content = base64.b64decode(data["content"]).decode('utf-8')
73
- file_extension = path.split('.')[-1].lower() if '.' in path else 'unknown'
74
-
75
- return {
76
- "success": True,
77
- "file_path": path,
78
- "file_name": path.split('/')[-1],
79
- "file_extension": file_extension,
80
- "content": content,
81
- "content_length": len(content),
82
- "line_count": len(content.split('\n')),
83
- "sha": data["sha"],
84
- "download_url": data.get("download_url", ""),
85
- "is_binary": False
86
- }
87
  except UnicodeDecodeError:
88
- return {
89
- "success": False,
90
- "error": "File contains binary data that cannot be decoded as text",
91
- "file_path": path,
92
- "is_binary": True
93
- }
94
  else:
95
- return {
96
- "success": False,
97
- "error": f"Path '{path}' is not a file or content is not available",
98
- "item_type": data.get("type", "unknown")
99
- }
100
  else:
101
- return {
102
- "success": False,
103
- "error": f"File not found or inaccessible (HTTP {response.status_code})",
104
- "file_path": path,
105
- "status_code": response.status_code
106
- }
107
 
108
  except Exception as e:
109
- return {
110
- "success": False,
111
- "error": f"Failed to fetch file content: {str(e)}",
112
- "file_path": path
113
- }
114
 
115
- def scan_repository(self, owner: str, repo: str, extensions: str = ".py,.js,.ts,.php,.java") -> dict:
116
- """Scan repository for code files"""
117
  try:
118
  ext_list = [ext.strip() for ext in extensions.split(",") if ext.strip()]
119
  all_files = []
120
  self._scan_directory_sync(owner, repo, "", ext_list, all_files)
121
 
122
- # Group files by extension for better organization
123
- files_by_extension = {}
124
- for file_info in all_files:
125
- ext = file_info.get('name', '').split('.')[-1].lower() if '.' in file_info.get('name', '') else 'no_extension'
126
- if ext not in files_by_extension:
127
- files_by_extension[ext] = []
128
- files_by_extension[ext].append(file_info)
129
-
130
- return {
131
- "success": True,
132
- "total_files_found": len(all_files),
133
- "extensions_scanned": ext_list,
134
- "files_by_extension": files_by_extension,
135
- "all_files": all_files[:100], # Limit to first 100 files
136
- "scan_summary": {
137
- "total_files": len(all_files),
138
- "extensions_found": list(files_by_extension.keys()),
139
- "largest_file": max(all_files, key=lambda x: x.get('size', 0)) if all_files else None
140
- }
141
- }
142
 
143
  except Exception as e:
144
- return {
145
- "success": False,
146
- "error": f"Failed to scan repository: {str(e)}",
147
- "total_files_found": 0
148
- }
149
 
150
  def _scan_directory_sync(self, owner: str, repo: str, path: str, extensions: List[str], all_files: List[Dict]):
151
  """Recursively scan directory for files"""
 
58
  "error": f"Failed to fetch repository information: {str(e)}"
59
  }
60
 
61
+ def get_file_content(self, owner: str, repo: str, path: str) -> str:
62
+ """Get content of a specific file - returns just the file content as string"""
63
  try:
64
  url = f"https://api.github.com/repos/{owner}/{repo}/contents/{path}"
65
  response = requests.get(url, headers=self.headers)
 
70
  # Decode base64 content
71
  try:
72
  content = base64.b64decode(data["content"]).decode('utf-8')
73
+ return content
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  except UnicodeDecodeError:
75
+ return f"ERROR: File '{path}' contains binary data that cannot be decoded as text"
 
 
 
 
 
76
  else:
77
+ return f"ERROR: Path '{path}' is not a file or content is not available"
 
 
 
 
78
  else:
79
+ return f"ERROR: File '{path}' not found or inaccessible (HTTP {response.status_code})"
 
 
 
 
 
80
 
81
  except Exception as e:
82
+ return f"ERROR: Failed to fetch file content for '{path}': {str(e)}"
 
 
 
 
83
 
84
+ def scan_repository(self, owner: str, repo: str, extensions: str = ".py,.js,.ts,.php,.java") -> list:
85
+ """Scan repository for code files - returns simple list of file paths"""
86
  try:
87
  ext_list = [ext.strip() for ext in extensions.split(",") if ext.strip()]
88
  all_files = []
89
  self._scan_directory_sync(owner, repo, "", ext_list, all_files)
90
 
91
+ # Return simple list of file paths for easier processing by CodeAgent
92
+ file_paths = [file_info.get('path', '') for file_info in all_files[:50]] # Limit to 50 files
93
+ return file_paths
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  except Exception as e:
96
+ return [f"ERROR: Failed to scan repository: {str(e)}"]
 
 
 
 
97
 
98
  def _scan_directory_sync(self, owner: str, repo: str, path: str, extensions: List[str], all_files: List[Dict]):
99
  """Recursively scan directory for files"""