Repository navigation
Expand file tree
/
Copy pathrelease_notes.go
More file actions
88 lines (82 loc) · 2.32 KB
/
Copy pathrelease_notes.go
File metadata and controls
88 lines (82 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2026 ysicing
// SPDX-License-Identifier: AGPL-3.0-only
package main
import "strings"
type releaseNoteGroups struct {
items map[string][]string
bytes int
includeVersions bool
}
func releaseCategory(heading string) string {
switch heading {
case "新功能", "新增", "新增功能":
return "新增功能"
case "改进", "功能改进":
return "功能改进"
case "修复", "问题修复":
return "问题修复"
case "废弃", "弃用", "已废弃":
return "已废弃"
case "移除", "已移除":
return "已移除"
default:
return "其他更新"
}
}
func (groups *releaseNoteGroups) add(version, notes string) bool {
category := "其他更新"
prefix := ""
suffix := ""
if groups.includeVersions {
suffix = " `v" + version + "`"
}
var lines []string
flush := func() bool {
if len(lines) == 0 {
return true
}
text := strings.Join(lines, "\n")
size := len("- ") + len(prefix) + len(text) + len(suffix) + len("\n")
if groups.bytes+size > maxUpdateManifest {
return false
}
item := "- " + prefix + text + suffix
groups.items[category] = append(groups.items[category], item)
groups.bytes += size
lines = lines[:0]
return true
}
for line := range strings.SplitSeq(strings.ReplaceAll(notes, "\r\n", "\n"), "\n") {
line = strings.TrimRight(line, " \t")
headingLine := strings.HasPrefix(line, "### ")
bullet := strings.HasPrefix(line, "- ") || strings.HasPrefix(line, "* ") || strings.HasPrefix(line, "+ ")
if (line == "" || headingLine || bullet) && !flush() {
return false
}
switch {
case line == "":
continue
case headingLine:
heading := strings.TrimSpace(strings.TrimPrefix(line, "### "))
category = releaseCategory(heading)
prefix = ""
if category == "其他更新" && heading != category {
prefix = heading + ":"
}
case bullet:
lines = append(lines, strings.TrimSpace(line[2:]))
default:
lines = append(lines, line)
}
}
return flush()
}
func (groups releaseNoteGroups) markdown() string {
var sections []string
for _, heading := range []string{"新增功能", "功能改进", "问题修复", "已废弃", "已移除", "其他更新"} {
if items := groups.items[heading]; len(items) > 0 {
sections = append(sections, "## "+heading+"\n\n"+strings.Join(items, "\n"))
}
}
return strings.Join(sections, "\n\n")
}