MCPcopy Create free account
hub / github.com/idosal/git-mcp / searchCode

Function searchCode

src/api/utils/githubClient.ts:245–268  ·  view source on GitHub ↗
(
  query: string,
  owner: string,
  repo: string,
  env: Env,
  page: number = 1,
  perPage: number = 20,
)

Source from the content-addressed store, hash-verified

243 * @param perPage - Results per page (max 100)
244 */
245export async function searchCode(
246 query: string,
247 owner: string,
248 repo: string,
249 env: Env,
250 page: number = 1,
251 perPage: number = 20,
252): Promise<any> {
253 // GitHub API has a max per_page of 100
254 const validPerPage = Math.min(Math.max(1, perPage), 100);
255
256 const searchUrl = `https://api.github.com/search/code?q=${encodeURIComponent(query)}+repo:${owner}/${repo}&page=${page}&per_page=${validPerPage}`;
257
258 const response = await githubApiRequest(searchUrl, {}, env);
259
260 if (!response || !response.ok) {
261 console.warn(
262 `GitHub API code search failed: ${response?.status} ${response?.statusText}`,
263 );
264 return null;
265 }
266
267 return response.json();
268}
269
270/**
271 * Search for a specific filename in a GitHub repository

Callers 1

searchRepositoryCodeFunction · 0.85

Calls 3

githubApiRequestFunction · 0.85
warnMethod · 0.80
jsonMethod · 0.80

Tested by

no test coverage detected