package governance import ( "strings" ) // Development headings cannot replace the formal release baseline. func ExtractDevelopmentNotes(changelog, version string) string { return developmentNotes(changelog, version, "") } func ExtractDevelopmentNotesForCommit(changelog, version, sha string) string { return developmentNotes(changelog, version, sha) } func developmentNotes(changelog, version, sha string) string { if !SemverValid(version) { return "" } lines := strings.Split(changelog, "\n") for i, line := range lines { if developmentHeadingMatches(line, version) { end := len(lines) for j := i + 1; j < len(lines); j++ { if strings.HasPrefix(lines[j], "## ") { end = j break } } body := strings.TrimSpace(strings.Join(lines[i+1:end], "\n")) if sha == "" { return body } for _, field := range lines[i+1 : end] { if strings.TrimSpace(field) == "目标提交:"+sha { return body } } } } return "" } // developmentHeadingMatches 接受两种真实标题: // - 旧格式:## 开发快照 snapshot/v0.1.1 - 2026-10-18 // - 开发快照:## 开发快照 0.1.351(索引预检使用目标映射 ID) // // 版本号后必须是字符串结束或分隔符,避免 0.1.35 命中 0.1.351; // 只读取到下一个二级标题,不跨版本吞正文。 func developmentHeadingMatches(line, version string) bool { prefixes := []string{ "## 开发快照 snapshot/v" + version, "## 开发快照 " + version, } for _, prefix := range prefixes { if !strings.HasPrefix(line, prefix) { continue } rest := line[len(prefix):] if rest == "" { return true } if strings.HasPrefix(rest, "—") || strings.HasPrefix(rest, "(") { return true } switch rest[0] { case ' ', '\t', '-', '(': return true } } return false }