searchGitHub queries the GitHub Code Search API for manifest files matching the query, using parallel search strategies mirroring gh skill search: - content match: filename: - path match: filename: path: - owner match: filename: user: (
(kind entities.Kind, query, owner string, limit int)
| 321 | // - owner match: filename:<manifest> user:<query> (when query looks like a GitHub user) |
| 322 | // - hyphen match: filename:<manifest> <hyphenated-query> (when query has spaces) |
| 323 | func searchGitHub(kind entities.Kind, query, owner string, limit int) ([]ghSearchResult, error) { |
| 324 | manifest := defaultManifestName(kind) |
| 325 | |
| 326 | ownerScope := "" |
| 327 | if owner != "" { |
| 328 | ownerScope = " user:" + owner |
| 329 | } |
| 330 | |
| 331 | contentQ := fmt.Sprintf("filename:%s %s%s", manifest, query, ownerScope) |
| 332 | pathTerm := strings.ReplaceAll(query, " ", "-") |
| 333 | pathQ := fmt.Sprintf("filename:%s path:%s%s", manifest, pathTerm, ownerScope) |
| 334 | |
| 335 | client := &http.Client{Timeout: 15 * time.Second} |
| 336 | authHeader := resolveGitHubAuth() |
| 337 | |
| 338 | var ( |
| 339 | contentItems []ghCodeSearchItem |
| 340 | contentErr error |
| 341 | pathItems []ghCodeSearchItem |
| 342 | pathErr error |
| 343 | ownerItems []ghCodeSearchItem |
| 344 | hyphenItems []ghCodeSearchItem |
| 345 | ) |
| 346 | |
| 347 | hasSpaces := strings.Contains(query, " ") |
| 348 | |
| 349 | var wg sync.WaitGroup |
| 350 | |
| 351 | // Path search (parallel). |
| 352 | wg.Add(1) |
| 353 | go func() { |
| 354 | defer wg.Done() |
| 355 | pathItems, pathErr = executeGHSearch(client, pathQ, limit, authHeader) |
| 356 | }() |
| 357 | |
| 358 | // Owner search: when no --owner flag and query looks like a GitHub user. |
| 359 | if owner == "" && couldBeGHOwner(query) { |
| 360 | ownerQ := fmt.Sprintf("filename:%s user:%s", manifest, query) |
| 361 | wg.Add(1) |
| 362 | go func() { |
| 363 | defer wg.Done() |
| 364 | ownerItems, _ = executeGHSearch(client, ownerQ, limit, authHeader) |
| 365 | }() |
| 366 | } |
| 367 | |
| 368 | // Hyphen search: when query has spaces (e.g. "mcp apps" → "mcp-apps"). |
| 369 | if hasSpaces { |
| 370 | hyphenQ := fmt.Sprintf("filename:%s %s%s", manifest, pathTerm, ownerScope) |
| 371 | wg.Add(1) |
| 372 | go func() { |
| 373 | defer wg.Done() |
| 374 | hyphenItems, _ = executeGHSearch(client, hyphenQ, limit, authHeader) |
| 375 | }() |
| 376 | } |
| 377 | |
| 378 | // Content search runs on the main goroutine. |
| 379 | contentItems, contentErr = executeGHSearch(client, contentQ, limit, authHeader) |
| 380 | wg.Wait() |
no test coverage detected