MCPcopy Create free account
hub / github.com/catppuccin/cli / UpdateJSON

Function UpdateJSON

internal/utils/network.go:50–86  ·  view source on GitHub ↗

UpdateJSON makes a search request for all Catppuccin repos and caches them.

()

Source from the content-addressed store, hash-verified

48
49// UpdateJSON makes a search request for all Catppuccin repos and caches them.
50func UpdateJSON() {
51 dir := path.Join(ShareDir(), "repos.json") // Set the staging directory plus the file name
52 org := GetEnv("ORG_OVERRIDE", "catppuccin")
53 client := github.NewClient(nil)
54
55 // Get all the Catppuccin repositories
56 opt := &github.RepositoryListByOrgOptions{Type: "public"} // Get all the repositories
57 repos, _, err := client.Repositories.ListByOrg(context.Background(), org, opt)
58
59 // Handle errors
60 if err != nil {
61 // fmt.Println("Failed to get repositories.")
62 log.Error("Failed to get repositories")
63 } else {
64 log.Info("Received repositories. Caching!")
65 themes := []structs.SearchEntry{}
66 for i := 0; i < len(repos); i++ {
67 repo := repos[i]
68 if !ListContains(repo.Topics, "catppuccin-meta") { // Repo does not contain catppuccin-meta topic
69 // Append search result
70 theme := structs.SearchEntry{
71 Name: repo.GetName(),
72 Stars: repo.GetStargazersCount(),
73 Topics: repo.Topics,
74 }
75 themes = append(themes, theme)
76 }
77 }
78 body, err := json.Marshal(themes)
79 if err != nil {
80 // fmt.Printf("Failed to marshal cache: %s\nPlease try again.\n", err)
81 log.Error("Failed to marshal cache. Please try again!")
82 } else {
83 os.WriteFile(dir, body, 0o644)
84 }
85 }
86}

Callers 1

searchPackageFunction · 0.92

Calls 5

ShareDirFunction · 0.85
GetEnvFunction · 0.85
ListContainsFunction · 0.85
ErrorMethod · 0.80
MarshalMethod · 0.80

Tested by

no test coverage detected