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

Function search_github_code

autoagent/tools/code_search.py:57–104  ·  view source on GitHub ↗

Search GitHub code based on a keyword. Args: repo_owner: The owner of the repository repo_name: The name of the repository query: The keyword to search for language: The programming language to filter by, optional per_page: The number of results

(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

55 return return_str
56@register_tool("search_github_code")
57def search_github_code(repo_owner: str,
58 repo_name: str,
59 query: str,
60 language: Optional[str] = None,
61 per_page: int = 5,
62 page: int = 1) -> List[Dict]:
63 """
64 Search GitHub code based on a keyword.
65
66 Args:
67 repo_owner: The owner of the repository
68 repo_name: The name of the repository
69 query: The keyword to search for
70 language: The programming language to filter by, optional
71 per_page: The number of results per page, optional
72 page: The page number, optional
73
74 Returns:
75 List[Dict]: The search results list
76 """
77 searcher = GitHubSearcher(GITHUB_AI_TOKEN)
78 results = searcher.search_code(repo_owner, repo_name, query, language, per_page, page)
79 # print(results)
80 if 'items' not in results:
81 return []
82
83 # Extract useful information
84 formatted_results = []
85 for item in results['items']:
86 response = requests.get(item['url'])
87 if response.status_code == 200:
88 download_url = response.json()['download_url']
89 response = requests.get(download_url)
90 if response.status_code == 200:
91 content = response.text
92 else:
93 content = ""
94 else:
95 content = ""
96 formatted_results.append({
97 'name': item['name'],
98 'path': item['path'],
99 'url': item['html_url'],
100 'repository': item['repository']['full_name'],
101 'content_url': item['url'],
102 'content': content
103 })
104 return json.dumps(formatted_results, indent=4)

Callers

nothing calls this directly

Calls 4

search_codeMethod · 0.95
GitHubSearcherClass · 0.90
getMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected