MCPcopy Create free account
hub / github.com/cli/cli / fetchRepoStars

Function fetchRepoStars

pkg/cmd/skills/search/search.go:892–935  ·  view source on GitHub ↗

fetchRepoStars fetches stargazer counts for each unique repository in the result set, using bounded concurrency.

(client *api.Client, host string, skills []skillResult)

Source from the content-addressed store, hash-verified

890// fetchRepoStars fetches stargazer counts for each unique repository in
891// the result set, using bounded concurrency.
892func fetchRepoStars(client *api.Client, host string, skills []skillResult) map[int]int {
893 const maxWorkers = 10
894 sem := make(chan struct{}, maxWorkers)
895 var wg sync.WaitGroup
896 var mu sync.Mutex
897
898 repoStars := make(map[string]int)
899 seen := make(map[string]bool)
900
901 for _, s := range skills {
902 if seen[s.Repo] {
903 continue
904 }
905 seen[s.Repo] = true
906
907 wg.Add(1)
908 go func(owner, repo, fullName string) {
909 defer wg.Done()
910 sem <- struct{}{}
911 defer func() { <-sem }()
912
913 apiPath, err := safeurl.JoinPath("repos", owner, repo)
914 if err != nil {
915 return
916 }
917 var info repoInfo
918 if err := client.REST(host, "GET", apiPath.String(), nil, &info); err != nil {
919 return
920 }
921 mu.Lock()
922 repoStars[fullName] = info.StargazersCount
923 mu.Unlock()
924 }(s.Owner, s.RepoName, s.Repo)
925 }
926 wg.Wait()
927
928 result := make(map[int]int, len(skills))
929 for i, s := range skills {
930 if stars, ok := repoStars[s.Repo]; ok {
931 result[i] = stars
932 }
933 }
934 return result
935}

Callers 1

enrichSkillsFunction · 0.85

Calls 6

JoinPathFunction · 0.92
AddMethod · 0.65
DoneMethod · 0.65
RESTMethod · 0.65
StringMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected