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

Class GitHubSearcher

autoagent/tools/github_client.py:70–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68
69
70class GitHubSearcher:
71 def __init__(self, token: Optional[str] = None):
72 """
73 Initialize the GitHub searcher
74
75 Args:
76 token: GitHub Personal Access Token, optional
77 """
78 self.session = requests.Session()
79 if token:
80 self.session.headers.update({
81 'Authorization': f'token {token}',
82 'Accept': 'application/vnd.github.v3+json'
83 })
84 self.session.headers.update({
85 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
86 })
87
88 # def search_code(self,
89 # repo_owner: str,
90 # repo_name: str,
91 # query: str,
92 # language: Optional[str] = None,
93 # per_page: int = 1) -> Dict:
94 # """
95 # Search code in a specific repository
96
97 # Args:
98 # repo_owner: The owner of the repository
99 # repo_name: The name of the repository
100 # query: The search keyword
101 # language: The programming language filter, optional
102 # per_page: The number of results per page
103
104 # Returns:
105 # dict: The search results
106 # """
107 # # Modify the search URL
108 # base_url = "https://api.github.com/search/code" # Modify here
109
110 # # Build the query parameters
111 # q = f"repo:{repo_owner}/{repo_name} {query}"
112 # if language:
113 # q += f" language:{language}"
114
115 # params = {
116 # 'q': q,
117 # 'per_page': per_page # add this parameter
118 # }
119
120 # try:
121 # response = self.session.get(base_url, params=params)
122 # response.raise_for_status() # Check if the request is successful
123
124 # # Handle rate limiting
125 # if 'X-RateLimit-Remaining' in response.headers:
126 # remaining = int(response.headers['X-RateLimit-Remaining'])
127 # if remaining < 10: # If the remaining requests are less, pause for a while

Callers 1

search_github_codeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected