Files
knowledge-governance/internal/governance/development_notes.go
T
姚章浩 2a2e98bd8e
build / build (push) Successful in 1m41s
fix(version): 兼容开发快照版本标题
识别“## 开发快照 <version>(说明)”并保留旧 snapshot/v 格式。
版本号精确匹配、不跨二级标题、空正文不返回,archive 精确 SHA 绑定不变。
2026-11-04 15:57:53 +08:00

71 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}