Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all newlines from changelog item output #263

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/changelog/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (cl *ChangeLog) PrintReleaseNotesForWriter(w io.Writer) {
return strings.ToLower(changelogItems[i]) < strings.ToLower(changelogItems[j])
})
for _, changeLogItem := range changelogItems {
cl.Logger.Printf(changeLogItem)
cl.Logger.Println(changeLogItem)
}
}
}
Expand Down
28 changes: 22 additions & 6 deletions pkg/github/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package github

import (
"bufio"
"fmt"
"sort"
"strconv"
Expand All @@ -29,27 +30,42 @@ const (
releaseNoteBlock = "```release-note"
upstreamPRsBlock = "```upstream-prs"
commentTag = "<!--"
endBlock = "```"
)

func textBlockBetween(body, str string) string {
lines := strings.Split(body, "\n")
// Get the text between startBlock and endBlock
func textBlockBetween(body, startBlock string) string {
// Use a bufio.Scanner to scan line by line because it handles both `\n` and `\r\n`.
scanner := bufio.NewScanner(strings.NewReader(body))
beginning, end := -1, -1
for idx, line := range lines {
idx := 0
gotBlock := false
var lines []string
for scanner.Scan() {
line := scanner.Text()
line = strings.TrimSpace(line)
if line == str {
lines = append(lines, line)
if line == startBlock {
beginning = idx
}
if beginning != -1 && line == "```" {
if !gotBlock && beginning != -1 && line == endBlock {
end = idx
break
// Got the block, but continue scanning so we can accumulate all the lines
gotBlock = true
}
if scanner.Err() != nil {
return ""
}
idx++
}

if beginning == end {
return ""
}
if end == -1 {
end = len(lines)
}

return strings.TrimSpace(strings.Join(lines[beginning+1:end], " "))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/github/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Test_getReleaseNote(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getReleaseNote(tt.args.title, tt.args.body); got != tt.want {
t.Errorf("getReleaseNote() = %v, want %v", got, tt.want)
t.Errorf("getReleaseNote() = %q, want %q", got, tt.want)
}
})
}
Expand Down