package update import ( "regexp" "strings" "time" ) var ( bulletLine = regexp.MustCompile(`^[-*+]\s+(.+)$`) markdownLink = regexp.MustCompile(`!?\[([^\]]*)\]\([^)]*\)`) boldText = regexp.MustCompile(`\*\*([^*]+)\*\*|__([^_]+)__`) italicText = regexp.MustCompile(`\*([^*\s][^*]*)\*`) inlineCode = regexp.MustCompile("`([^`]*)`") ) func BuildNotes(tag string, publishedAt time.Time, body string) ReleaseNotes { items := []string{} for _, line := range strings.Split(body, "\n") { match := bulletLine.FindStringSubmatch(strings.TrimSpace(line)) if match == nil { continue } if item := plainText(match[1]); item != "" { items = append(items, item) } } return ReleaseNotes{Version: tag, ReleasedAt: publishedAt, Items: items} } func plainText(markdown string) string { text := markdownLink.ReplaceAllString(markdown, "$1") text = boldText.ReplaceAllString(text, "$1$2") text = italicText.ReplaceAllString(text, "$1") text = inlineCode.ReplaceAllString(text, "$1") return strings.TrimSpace(text) }