mirror of
https://github.com/tiennm99/awesome-ai-dev-tools.git
synced 2026-10-11 03:13:05 +00:00
README.md and site/data.json were written with os.Create/os.WriteFile, so a write that failed midway left the repo front page truncated, while history.jsonl already used a temp-file-plus-rename. Extract that pattern into atomicWriteFile and route all three writers through it. Also sort snapshots by date when reading history.jsonl: delta windows pick the newest snapshot inside the window by scan order, which silently produces wrong deltas if a hand edit or a merge of two concurrent runs interleaves lines. Cover the README renderer, which had no test beyond sanitizeCell, and name the generated paths as constants instead of repeating literals. Coverage 65.1% -> 75.7%.
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
)
|
|
|
|
// siteRow is one ranked repo in site/data.json, consumed by site/index.html.
|
|
type siteRow struct {
|
|
Key string `json:"key"` // canonical owner/repo, matches history keys
|
|
NameWithOwner string `json:"nameWithOwner"`
|
|
URL string `json:"url"`
|
|
Stars int `json:"stars"`
|
|
Delta7d int `json:"delta7d"`
|
|
HasDelta bool `json:"hasDelta"`
|
|
Delta30d int `json:"delta30d"`
|
|
HasDelta30 bool `json:"hasDelta30"`
|
|
Language string `json:"language"`
|
|
PushedAt string `json:"pushedAt"`
|
|
Description string `json:"description"`
|
|
Category string `json:"category"`
|
|
Notes string `json:"notes,omitempty"`
|
|
Archived bool `json:"archived"`
|
|
}
|
|
|
|
type siteData struct {
|
|
UpdatedAt string `json:"updatedAt"`
|
|
Rows []siteRow `json:"rows"`
|
|
History []Snapshot `json:"history"`
|
|
}
|
|
|
|
// writeSiteData emits the JSON payload for the GitHub Pages dashboard.
|
|
// The file is generated fresh on every updater run and is not committed;
|
|
// the Pages deploy step in the workflow picks it up from the working tree.
|
|
func writeSiteData(path string, stats []Stat, deltas7, deltas30 map[string]int, history []Snapshot) error {
|
|
rows := make([]siteRow, len(stats))
|
|
for i, s := range stats {
|
|
delta7, has7 := deltas7[s.CanonicalKey]
|
|
delta30, has30 := deltas30[s.CanonicalKey]
|
|
rows[i] = siteRow{
|
|
Key: s.CanonicalKey,
|
|
NameWithOwner: s.NameWithOwner,
|
|
URL: s.URL,
|
|
Stars: s.Stars,
|
|
Delta7d: delta7,
|
|
HasDelta: has7,
|
|
Delta30d: delta30,
|
|
HasDelta30: has30,
|
|
Language: s.Language,
|
|
PushedAt: s.PushedAt.Format("2006-01-02"),
|
|
Description: s.Description,
|
|
Category: s.Category,
|
|
Notes: s.Notes,
|
|
Archived: s.IsArchived,
|
|
}
|
|
}
|
|
|
|
return atomicWriteFile(path, func(w io.Writer) error {
|
|
return json.NewEncoder(w).Encode(siteData{
|
|
UpdatedAt: timeNow().UTC().Format("2006-01-02 15:04 UTC"),
|
|
Rows: rows,
|
|
History: history,
|
|
})
|
|
})
|
|
}
|