( query: string, owner: string, repo: string, env: Env, page: number = 1, perPage: number = 20, )
| 243 | * @param perPage - Results per page (max 100) |
| 244 | */ |
| 245 | export 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 |
no test coverage detected