Skip to content

Commit 30f71f8

Browse files
committed
Fix extraction to account for comments in code blocks
1 parent a1f9489 commit 30f71f8

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

make_release/notes/generate.nu

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,31 @@ export def get-release-notes []: record -> record {
8888
$pr | insert notes $notes
8989
}
9090

91+
# Create closure for `reduce` to extract the whole release notes summary.
92+
def extract_until_end []: nothing -> closure {
93+
let terminators = ["# " "## " "---"]
94+
{|line: string, state: record|
95+
mut state = $state
96+
97+
if $state.done { return $state }
98+
99+
# check if we're entering/exiting a code block
100+
# this might be kind of brittle
101+
if $line has "```" {
102+
$state.code = not $state.code
103+
}
104+
105+
let found_terminator = $terminators | any { $line starts-with $in }
106+
if $found_terminator and not $state.code {
107+
$state.done = true
108+
return $state
109+
}
110+
111+
$state.out ++= [$line]
112+
$state
113+
}
114+
}
115+
91116
# Extracts the "Release notes summary" section of the PR description
92117
export def extract-notes []: string -> string {
93118
lines
@@ -96,10 +121,9 @@ export def extract-notes []: string -> string {
96121
# this should already have been checked
97122
| if ($in | is-empty) { assert false } else {}
98123
| skip 1 # remove header
99-
# extract until next heading
100-
| take until {
101-
$in starts-with "# " or $in starts-with "## " or $in starts-with "---"
102-
}
124+
# extract until end of summary
125+
| reduce -f {code: false, done: false, out: []} (extract_until_end)
126+
| get out
103127
| str join (char nl)
104128
# remove HTML comments
105129
| str replace -amr '<!--\O*?-->' ''

0 commit comments

Comments
 (0)