MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / enrichGHDescriptions

Function enrichGHDescriptions

internal/cli/management.go:528–634  ·  view source on GitHub ↗

enrichGHDescriptions fetches SKILL.md blob content to extract the frontmatter description field concurrently with bounded parallelism, and also fetches star counts for unique repos (mirroring gh skill search enrichment).

(client *http.Client, authHeader string, results []ghSearchResult)

Source from the content-addressed store, hash-verified

526// description field concurrently with bounded parallelism, and also fetches
527// star counts for unique repos (mirroring gh skill search enrichment).
528func enrichGHDescriptions(client *http.Client, authHeader string, results []ghSearchResult) {
529 const maxWorkers = 10
530 sem := make(chan struct{}, maxWorkers)
531
532 // Fetch descriptions concurrently.
533 var descWG sync.WaitGroup
534 for i := range results {
535 parts := strings.SplitN(results[i].Repo, "/", 2)
536 if len(parts) != 2 {
537 continue
538 }
539 descWG.Add(1)
540 go func(idx int, owner, repo, path string) {
541 defer descWG.Done()
542 sem <- struct{}{}
543 defer func() { <-sem }()
544
545 rawURL := fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/main/%s",
546 owner, repo, path)
547 req, err := http.NewRequest("GET", rawURL, nil)
548 if err != nil {
549 return
550 }
551 req.Header.Set("User-Agent", "code-agent-manager")
552 if authHeader != "" {
553 req.Header.Set("Authorization", authHeader)
554 }
555 resp, err := client.Do(req)
556 if err != nil || resp.StatusCode != 200 {
557 if resp != nil {
558 resp.Body.Close()
559 }
560 return
561 }
562 body, err := io.ReadAll(io.LimitReader(resp.Body, 4096))
563 resp.Body.Close()
564 if err != nil {
565 return
566 }
567 desc := extractFrontmatterDescription(string(body))
568 if desc != "" {
569 results[idx].Description = desc
570 }
571 }(i, parts[0], parts[1], results[i].Path)
572 }
573
574 // Fetch star counts for unique repos concurrently.
575 type repoKey struct{ owner, name string }
576 repoStars := make(map[string]int)
577 var starsMu sync.Mutex
578 seen := make(map[string]bool)
579
580 var starsWG sync.WaitGroup
581 for _, r := range results {
582 if seen[r.Repo] {
583 continue
584 }
585 seen[r.Repo] = true

Callers 1

searchGitHubFunction · 0.85

Calls 3

SetMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected