Skip to content

Commit 3fc2e47

Browse files
arimxyerclaude
andcommitted
Simplify Source struct with Owner/Repo fields and methods
- Remove redundant Name field (map key serves same purpose) - Replace FetchFunc with Fetch() method using Owner/Repo - Add URL() method to generate release URL from Owner/Repo - Remove 5 wrapper functions (fetchClaudeChangelog, etc.) - Sources map is now 5 clean one-liners Adding a new source now requires only one line of config. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 90c8f4d commit 3fc2e47

File tree

1 file changed

+21
-59
lines changed

1 file changed

+21
-59
lines changed

main.go

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,25 @@ type ChangelogEntry struct {
3030
}
3131

3232
type Source struct {
33-
Name string
3433
DisplayName string
35-
URL string
36-
FetchFunc func() ([]ChangelogEntry, error)
34+
Owner string
35+
Repo string
36+
}
37+
38+
func (s Source) URL() string {
39+
return fmt.Sprintf("https://github.com/%s/%s/releases", s.Owner, s.Repo)
40+
}
41+
42+
func (s Source) Fetch() ([]ChangelogEntry, error) {
43+
return fetchGitHubReleases(s.Owner, s.Repo)
3744
}
3845

3946
var sources = map[string]Source{
40-
"claude": {
41-
Name: "claude",
42-
DisplayName: "Claude Code",
43-
URL: "https://github.com/anthropics/claude-code/releases",
44-
FetchFunc: fetchClaudeChangelog,
45-
},
46-
"codex": {
47-
Name: "codex",
48-
DisplayName: "OpenAI Codex",
49-
URL: "https://github.com/openai/codex/releases",
50-
FetchFunc: fetchCodexChangelog,
51-
},
52-
"opencode": {
53-
Name: "opencode",
54-
DisplayName: "OpenCode",
55-
URL: "https://github.com/sst/opencode/releases",
56-
FetchFunc: fetchOpenCodeChangelog,
57-
},
58-
"gemini": {
59-
Name: "gemini",
60-
DisplayName: "Gemini CLI",
61-
URL: "https://github.com/google-gemini/gemini-cli/releases",
62-
FetchFunc: fetchGeminiChangelog,
63-
},
64-
"copilot": {
65-
Name: "copilot",
66-
DisplayName: "GitHub Copilot CLI",
67-
URL: "https://github.com/github/copilot-cli/releases",
68-
FetchFunc: fetchCopilotChangelog,
69-
},
47+
"claude": {DisplayName: "Claude Code", Owner: "anthropics", Repo: "claude-code"},
48+
"codex": {DisplayName: "OpenAI Codex", Owner: "openai", Repo: "codex"},
49+
"opencode": {DisplayName: "OpenCode", Owner: "sst", Repo: "opencode"},
50+
"gemini": {DisplayName: "Gemini CLI", Owner: "google-gemini", Repo: "gemini-cli"},
51+
"copilot": {DisplayName: "GitHub Copilot CLI", Owner: "github", Repo: "copilot-cli"},
7052
}
7153

7254
func main() {
@@ -101,7 +83,7 @@ func main() {
10183
}
10284
if webOpen {
10385
for _, src := range sources {
104-
openBrowser(src.URL)
86+
openBrowser(src.URL())
10587
}
10688
os.Exit(0)
10789
}
@@ -121,7 +103,7 @@ func main() {
121103
}
122104
if webOpen {
123105
for _, src := range sources {
124-
openBrowser(src.URL)
106+
openBrowser(src.URL())
125107
}
126108
os.Exit(0)
127109
}
@@ -162,11 +144,11 @@ func main() {
162144
}
163145

164146
if webOpen {
165-
openBrowser(source.URL)
147+
openBrowser(source.URL())
166148
os.Exit(0)
167149
}
168150

169-
entries, err := source.FetchFunc()
151+
entries, err := source.Fetch()
170152
if err != nil {
171153
fmt.Fprintf(os.Stderr, "Error fetching changelog: %v\n", err)
172154
os.Exit(1)
@@ -259,7 +241,7 @@ func runLatestCommand(jsonOutput bool) {
259241
wg.Add(1)
260242
go func(name string, src Source) {
261243
defer wg.Done()
262-
entries, err := src.FetchFunc()
244+
entries, err := src.Fetch()
263245
if err != nil {
264246
results <- result{source: name, display: src.DisplayName, err: err}
265247
return
@@ -328,7 +310,7 @@ func runStatusCommand(jsonOutput bool) {
328310
wg.Add(1)
329311
go func(name string, src Source) {
330312
defer wg.Done()
331-
entries, err := src.FetchFunc()
313+
entries, err := src.Fetch()
332314
results <- statusResult{
333315
source: name,
334316
displayName: src.DisplayName,
@@ -571,26 +553,6 @@ func calculateAvgReleaseFreq(entries []ChangelogEntry) string {
571553
return fmt.Sprintf("~%dmo", months)
572554
}
573555

574-
func fetchClaudeChangelog() ([]ChangelogEntry, error) {
575-
return fetchGitHubReleases("anthropics", "claude-code")
576-
}
577-
578-
func fetchCodexChangelog() ([]ChangelogEntry, error) {
579-
return fetchGitHubReleases("openai", "codex")
580-
}
581-
582-
func fetchOpenCodeChangelog() ([]ChangelogEntry, error) {
583-
return fetchGitHubReleases("sst", "opencode")
584-
}
585-
586-
func fetchGeminiChangelog() ([]ChangelogEntry, error) {
587-
return fetchGitHubReleases("google-gemini", "gemini-cli")
588-
}
589-
590-
func fetchCopilotChangelog() ([]ChangelogEntry, error) {
591-
return fetchGitHubReleases("github", "copilot-cli")
592-
}
593-
594556
func fetchGitHubReleases(owner, repo string) ([]ChangelogEntry, error) {
595557
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases", owner, repo)
596558

0 commit comments

Comments
 (0)