chore(go): route release notes through vociferate
This commit is contained in:
@@ -215,6 +215,11 @@ func UnreleasedBody(rootDir string, options Options) (string, error) {
|
||||
return defaultService().UnreleasedBody(rootDir, options)
|
||||
}
|
||||
|
||||
// ReleaseNotes returns the release section for a specific semantic version.
|
||||
func ReleaseNotes(rootDir, version string, options Options) (string, error) {
|
||||
return defaultService().ReleaseNotes(rootDir, version, options)
|
||||
}
|
||||
|
||||
// RecommendedTag returns the next semantic release tag based on current changelog state.
|
||||
func (s *Service) RecommendedTag(rootDir string, options Options) (string, error) {
|
||||
resolved, err := resolveOptions(options)
|
||||
@@ -281,6 +286,16 @@ func (s *Service) UnreleasedBody(rootDir string, options Options) (string, error
|
||||
return s.readUnreleasedBody(rootDir, resolved.Changelog)
|
||||
}
|
||||
|
||||
// ReleaseNotes returns the release section for a specific semantic version.
|
||||
func (s *Service) ReleaseNotes(rootDir, version string, options Options) (string, error) {
|
||||
resolved, err := resolveOptions(options)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return s.readReleaseNotes(rootDir, strings.TrimPrefix(strings.TrimSpace(version), "v"), resolved.Changelog)
|
||||
}
|
||||
|
||||
func sectionHasEntries(unreleasedBody, sectionName string) bool {
|
||||
heading := "### " + sectionName
|
||||
sectionStart := strings.Index(unreleasedBody, heading)
|
||||
@@ -471,6 +486,10 @@ func readLatestChangelogVersion(rootDir, changelogPath string) (string, bool, er
|
||||
return defaultService().readLatestChangelogVersion(rootDir, changelogPath)
|
||||
}
|
||||
|
||||
func readReleaseNotes(rootDir, version, changelogPath string) (string, error) {
|
||||
return defaultService().readReleaseNotes(rootDir, version, changelogPath)
|
||||
}
|
||||
|
||||
func (s *Service) readLatestChangelogVersion(rootDir, changelogPath string) (string, bool, error) {
|
||||
path := filepath.Join(rootDir, changelogPath)
|
||||
contents, err := s.fileSystem.ReadFile(path)
|
||||
@@ -485,6 +504,38 @@ func (s *Service) readLatestChangelogVersion(rootDir, changelogPath string) (str
|
||||
return match[1], true, nil
|
||||
}
|
||||
|
||||
func (s *Service) readReleaseNotes(rootDir, version, changelogPath string) (string, error) {
|
||||
if version == "" {
|
||||
return "", fmt.Errorf("release version must not be empty")
|
||||
}
|
||||
|
||||
path := filepath.Join(rootDir, changelogPath)
|
||||
contents, err := s.fileSystem.ReadFile(path)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("read changelog: %w", err)
|
||||
}
|
||||
|
||||
text := string(contents)
|
||||
headingExpr := regexp.MustCompile(`(?m)^## \[` + regexp.QuoteMeta(version) + `\](?:\([^\n)]*\))? - `)
|
||||
headingLoc := headingExpr.FindStringIndex(text)
|
||||
if headingLoc == nil {
|
||||
return "", fmt.Errorf("release notes section for %s not found in changelog", version)
|
||||
}
|
||||
|
||||
nextSectionRelative := strings.Index(text[headingLoc[0]+1:], "\n## [")
|
||||
sectionEnd := len(text)
|
||||
if nextSectionRelative != -1 {
|
||||
sectionEnd = headingLoc[0] + 1 + nextSectionRelative
|
||||
}
|
||||
|
||||
section := text[headingLoc[0]:sectionEnd]
|
||||
if !strings.HasSuffix(section, "\n") {
|
||||
section += "\n"
|
||||
}
|
||||
|
||||
return section, nil
|
||||
}
|
||||
|
||||
func deriveRepositoryURL(rootDir string) (string, bool) {
|
||||
return defaultService().deriveRepositoryURL(rootDir)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user