UpdateJSON makes a search request for all Catppuccin repos and caches them.
()
| 48 | |
| 49 | // UpdateJSON makes a search request for all Catppuccin repos and caches them. |
| 50 | func 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 | } |
no test coverage detected