MCPcopy Create free account
hub / github.com/HKUDS/AutoAgent / search_code

Method search_code

autoagent/tools/github_client.py:159–194  ·  view source on GitHub ↗

搜索代码

(self, 
                    repo_owner: str, 
                    repo_name: str, 
                    query: str, 
                    language: Optional[str] = None,
                    per_page: int = 5, 
                    page: int = 1)

Source from the content-addressed store, hash-verified

157 # except requests.exceptions.RequestException as e:
158 # return f"Failed to get file content: {str(e)}"
159 def search_code(self,
160 repo_owner: str,
161 repo_name: str,
162 query: str,
163 language: Optional[str] = None,
164 per_page: int = 5,
165 page: int = 1) -> Dict:
166 """搜索代码"""
167 base_url = "https://api.github.com/search/code"
168
169 # 构建查询
170 q = f"repo:{repo_owner}/{repo_name} {query}"
171 if language:
172 q += f" language:{language}"
173
174 params = {
175 'q': q,
176 'per_page': min(per_page, 100), # 确保不超过最大限制
177 'page': page
178 }
179
180 try:
181 response = self.session.get(base_url, params=params)
182 response.raise_for_status()
183
184 # 处理速率限制
185 self._handle_rate_limit(response.headers)
186
187 return response.json()
188
189 except requests.exceptions.RequestException as e:
190 return {
191 'status': 'error',
192 'message': f"Request failed: {str(e)}",
193 'items': []
194 }
195
196 def get_contents_batch(self, items: List[Dict]) -> List[Dict]:
197 """批量获取文件内容"""

Callers 1

search_github_codeFunction · 0.95

Calls 2

_handle_rate_limitMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected