Skip to content

Commit 5d5c923

Browse files
cptpiepmatz132ikl
andauthored
Some release notes generation fixes (#1227)
Co-authored-by: 132ikl <132@ikl.sh>
1 parent b45b000 commit 5d5c923

3 files changed

Lines changed: 59 additions & 17 deletions

File tree

make_release/notes/create-pr.nu

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ by opening PRs against the `release-notes-($version)` branch.
9292
}
9393

9494
log info "setting up nushell.github.io repo"
95-
^git clone https://github.com/nushell/nushell.github.io $repo --origin nushell --branch main --single-branch
96-
^git -C $repo remote set-url nushell --push git@github.com:nushell/nushell.github.io.git
95+
^gh repo clone nushell/nushell.github.io $repo -- --origin nushell --branch main --single-branch --depth 1
9796

9897
log info "creating release branch"
9998
^git -C $repo checkout -b $branch

make_release/notes/generate.nu

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ export def extract-notes []: string -> string {
9696
# this should already have been checked
9797
| if ($in | is-empty) { assert false } else {}
9898
| 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-
}
99+
# extract until end of summary
100+
| reduce -f {code: false, done: false, out: []} (extract_until_end)
101+
| get out
103102
| str join (char nl)
104103
# remove HTML comments
105104
| str replace -amr '<!--\O*?-->' ''
@@ -157,7 +156,7 @@ export def generate-section []: record<section: string, prs: table> -> string {
157156
}
158157

159158
# Add single-line summaries
160-
if ($multiline | is-not-empty) {
159+
if ($multiline | is-not-empty) and ($bullet | is-not-empty) {
161160
$body ++= [$"### ($section.h3)\n"]
162161
}
163162
$body ++= $bullet | each {|pr| "* " ++ $pr.notes ++ $" \(($pr | pr-link)\)" }
@@ -184,6 +183,31 @@ export def generate-full-changelog [version: string]: nothing -> string {
184183
| pr-table
185184
}
186185

186+
# Create closure for `reduce` to extract the whole release notes summary.
187+
def extract_until_end []: nothing -> closure {
188+
let terminators = ["# " "## " "---"]
189+
{|line: string, state: record|
190+
mut state = $state
191+
192+
if $state.done { return $state }
193+
194+
# check if we're entering/exiting a code block
195+
# this might be kind of brittle
196+
if $line has "```" {
197+
$state.code = not $state.code
198+
}
199+
200+
let found_terminator = $terminators | any { $line starts-with $in }
201+
if $found_terminator and not $state.code {
202+
$state.done = true
203+
return $state
204+
}
205+
206+
$state.out ++= [$line]
207+
$state
208+
}
209+
}
210+
187211
# Get section labels which don't have a corresponding heading (i.e., don't appear in Changes section)
188212
def labels-without-heading [] {
189213
$SECTIONS | where h2 == null | get label

make_release/notes/tools.nu

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ def query-prs [
4545

4646
let query = $query_parts | str join ' '
4747

48-
(gh --repo $repo pr list --state merged
49-
--limit (inf | into int)
50-
--json author,title,number,mergedAt,url,body,labels
51-
--search $query)
52-
| from json
48+
let results = (
49+
gh --repo $repo pr list --state merged
50+
--limit (inf | into int)
51+
--json author,title,number,mergedAt,url,body,labels
52+
--search $query
53+
| from json
54+
)
55+
56+
assert ($results | is-not-empty) "Query returned no results"
57+
$results
5358
}
5459

5560
# Generate the release notes for the specified version.
@@ -148,11 +153,9 @@ export def write-toc [file: path] {
148153
| each {|header|
149154
let indent = '- ' | fill -w ($header.level * 2) -a right
150155

151-
let text = $header.line | str trim -l -c '#' | str trim -l
152-
let text = if $text ends-with $toc {
153-
$text | str substring ..<(-1 * ($toc | str length)) | str trim -r
154-
} else {
155-
$text
156+
mut text = $header.line | str trim -l -c '#' | str trim -l
157+
if $text ends-with $toc {
158+
$text = $text | str substring ..<(-1 * ($toc | str length)) | str trim -r
156159
}
157160

158161
let link = (
@@ -161,6 +164,22 @@ export def write-toc [file: path] {
161164
| str kebab-case
162165
)
163166

167+
# remove PR link from header, if applicable
168+
let regex = r#'(?x) # verbose mode
169+
(?<text>.+?) # the actual header text
170+
\s+
171+
\( # start PR link
172+
\[\#\d+\] # PR number component
173+
(?: # optional non-capturing group
174+
\(.+?\) # link to PR
175+
)? # end group
176+
\)
177+
'#
178+
let prlink = $text | parse -r $regex
179+
if ($prlink | is-not-empty) {
180+
$text = $prlink.0.text
181+
}
182+
164183
$"($indent)[_($text)_]\(#($link)-toc\)"
165184
}
166185
)

0 commit comments

Comments
 (0)