Skip to content

Commit 244c213

Browse files
committed
Fix Claude changelog parsing for new date format
1 parent d3ab722 commit 244c213

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

main.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ func fetchClaudeChangelog() ([]ChangelogEntry, error) {
270270
return nil, err
271271
}
272272

273-
entries := parseMarkdownChangelog(content, `(?m)^## (\d+\.\d+\.\d+)\s*$`)
273+
// Regex: ## 1.2.3 or ## 1.2.3 (2024-01-07)
274+
entries := parseMarkdownChangelogWithOptionalDate(content, `(?m)^## (\d+\.\d+\.\d+)(?:\s+\((\d{4}-\d{2}-\d{2})\))?\s*$`)
274275

275-
// Fetch last commit date for the changelog file
276-
if len(entries) > 0 {
276+
if len(entries) > 0 && entries[0].ReleasedAt.IsZero() {
277277
commitDate := fetchGitHubFileLastCommitDate("anthropics", "claude-code", "CHANGELOG.md")
278278
if !commitDate.IsZero() {
279279
entries[0].ReleasedAt = commitDate
@@ -503,6 +503,40 @@ func parseMarkdownChangelogWithDate(content, versionPattern string) []ChangelogE
503503
return entries
504504
}
505505

506+
func parseMarkdownChangelogWithOptionalDate(content, versionPattern string) []ChangelogEntry {
507+
var entries []ChangelogEntry
508+
509+
versionRegex := regexp.MustCompile(versionPattern)
510+
matches := versionRegex.FindAllStringSubmatch(content, -1)
511+
matchIndexes := versionRegex.FindAllStringSubmatchIndex(content, -1)
512+
513+
for i, match := range matches {
514+
ver := match[1]
515+
var releasedAt time.Time
516+
if len(match) > 2 && match[2] != "" {
517+
releasedAt, _ = time.Parse("2006-01-02", match[2])
518+
}
519+
520+
var contentEnd int
521+
if i+1 < len(matchIndexes) {
522+
contentEnd = matchIndexes[i+1][0]
523+
} else {
524+
contentEnd = len(content)
525+
}
526+
527+
sectionContent := content[matchIndexes[i][1]:contentEnd]
528+
changes := parseChanges(sectionContent)
529+
530+
entries = append(entries, ChangelogEntry{
531+
Version: ver,
532+
ReleasedAt: releasedAt,
533+
Changes: changes,
534+
})
535+
}
536+
537+
return entries
538+
}
539+
506540
func parseChanges(content string) []string {
507541
var changes []string
508542
lines := strings.Split(content, "\n")

0 commit comments

Comments
 (0)