MCPcopy Create free account
hub / github.com/atripati/ark / simplifyRepoListWithLang

Function simplifyRepoListWithLang

pkg/tools/github.go:681–722  ·  view source on GitHub ↗

simplifyRepoListWithLang filters results to match the requested language.

(raw string, requestedLang string)

Source from the content-addressed store, hash-verified

679
680// simplifyRepoListWithLang filters results to match the requested language.
681func simplifyRepoListWithLang(raw string, requestedLang string) (string, error) {
682 if requestedLang == "" {
683 return simplifyRepoList(raw)
684 }
685
686 // Parse the raw response first
687 var repos []map[string]interface{}
688
689 var searchResult map[string]interface{}
690 if err := json.Unmarshal([]byte(raw), &searchResult); err == nil {
691 if items, ok := searchResult["items"].([]interface{}); ok {
692 for _, item := range items {
693 if m, ok := item.(map[string]interface{}); ok {
694 repos = append(repos, m)
695 }
696 }
697 }
698 }
699 if len(repos) == 0 {
700 if err := json.Unmarshal([]byte(raw), &repos); err != nil {
701 return raw, nil
702 }
703 }
704
705 // Hard filter: only keep repos that match the requested language
706 langLower := strings.ToLower(requestedLang)
707 filtered := make([]map[string]interface{}, 0)
708 for _, r := range repos {
709 repoLang := strings.ToLower(fmt.Sprintf("%v", r["language"]))
710 if repoLang == langLower || repoLang == "" {
711 filtered = append(filtered, r)
712 }
713 }
714
715 // Re-encode as array for simplifyRepoList
716 data, err := json.Marshal(filtered)
717 if err != nil {
718 return simplifyRepoList(raw)
719 }
720
721 return simplifyRepoList(string(data))
722}
723
724// detectLanguage extracts a programming language name from a natural language query.
725func detectLanguage(query string) string {

Callers

nothing calls this directly

Calls 1

simplifyRepoListFunction · 0.85

Tested by

no test coverage detected