MCPcopy Index your code
hub / github.com/coder/coder / parseCalendarTable

Function parseCalendarTable

scripts/releaser/docs.go:53–104  ·  view source on GitHub ↗

parseCalendarTable extracts calendar rows from the markdown between the start and end markers. Returns the rows and the column widths for re-rendering.

(content string)

Source from the content-addressed store, hash-verified

51// between the start and end markers. Returns the rows and the
52// column widths for re-rendering.
53func parseCalendarTable(content string) ([]calendarRow, error) {
54 startIdx := strings.Index(content, calendarStartMarker)
55 endIdx := strings.Index(content, calendarEndMarker)
56 if startIdx == -1 || endIdx == -1 {
57 return nil, xerrors.New("calendar markers not found")
58 }
59
60 tableContent := content[startIdx+len(calendarStartMarker) : endIdx]
61 lines := strings.Split(strings.TrimSpace(tableContent), "\n")
62
63 var rows []calendarRow
64 for _, line := range lines {
65 line = strings.TrimSpace(line)
66 if line == "" {
67 continue
68 }
69 // Skip header and separator lines.
70 if strings.HasPrefix(line, "| Release") ||
71 strings.HasPrefix(line, "|---") ||
72 strings.HasPrefix(line, "|-") {
73 continue
74 }
75 if !strings.HasPrefix(line, "|") {
76 continue
77 }
78
79 cols := strings.Split(line, "|")
80 // Split on "|" gives empty first and last elements.
81 if len(cols) < 5 {
82 continue
83 }
84 name := strings.TrimSpace(cols[1])
85 date := strings.TrimSpace(cols[2])
86 status := strings.TrimSpace(cols[3])
87 latest := strings.TrimSpace(cols[4])
88
89 major, minor := parseReleaseName(name)
90 rows = append(rows, calendarRow{
91 ReleaseName: name,
92 Major: major,
93 Minor: minor,
94 ReleaseDate: date,
95 Status: status,
96 LatestRelease: latest,
97 })
98 }
99
100 if len(rows) == 0 {
101 return nil, xerrors.New("no calendar rows found")
102 }
103 return rows, nil
104}
105
106// parseReleaseName extracts major.minor from a release name
107// like "2.30" or "[2.30](https://...)".

Callers 1

updateCalendarFileFunction · 0.85

Calls 2

parseReleaseNameFunction · 0.85
NewMethod · 0.65

Tested by

no test coverage detected