mirror of
https://github.com/go-task/task.git
synced 2026-08-29 10:08:27 +02:00
feat(release): generate the GitHub release body from the changelog (#2987)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
48
cmd/release/notes.go
Normal file
48
cmd/release/notes.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
)
|
||||
|
||||
func notes(w io.Writer) error {
|
||||
version, err := getVersion(versionFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b, err := os.ReadFile(changelogSource)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
section := changelogSection(string(b), version)
|
||||
if section == "" {
|
||||
return nil
|
||||
}
|
||||
_, err = fmt.Fprintln(w, section)
|
||||
return err
|
||||
}
|
||||
|
||||
func changelogSection(changelog string, version *semver.Version) string {
|
||||
heading := fmt.Sprintf("## v%s ", version)
|
||||
var section []string
|
||||
var found bool
|
||||
for line := range strings.SplitSeq(changelog, "\n") {
|
||||
if strings.HasPrefix(line, "## ") {
|
||||
if found {
|
||||
break
|
||||
}
|
||||
found = strings.HasPrefix(line, heading)
|
||||
continue
|
||||
}
|
||||
if found {
|
||||
section = append(section, line)
|
||||
}
|
||||
}
|
||||
return strings.TrimSpace(strings.Join(section, "\n"))
|
||||
}
|
||||
Reference in New Issue
Block a user