Skip to content

Commit b4154c8

Browse files
🩹 [Patch]: Refactor release notes handling to improve clarity and structure (#81)
## Description This pull request refactors the logic for constructing release notes in `scripts/main.ps1` to improve clarity and maintainability. The changes separate the handling of PR title and body into distinct blocks and ensure that notes are only added when they are non-empty. ### Improvements to release notes construction: * Refactored the logic to initialize `$notes` as an empty string and append the PR title and body conditionally, instead of combining them in a single step. This improves readability and modularity. * Added a check to ensure that `$notes` is non-empty before appending it to the `$releaseCreateCommand`, preventing unnecessary arguments when no notes are provided. * Enhanced debugging output by including the constructed `gh` arguments for better traceability during execution.
1 parent 09e7eaf commit b4154c8

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

‎scripts/main.ps1

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -233,39 +233,39 @@ if ($createPrerelease -or $createRelease -or $whatIf) {
233233
}
234234

235235
# Build release creation command with options
236-
$releaseCreateCommand = @("release", "create", "$newVersion")
236+
$releaseCreateCommand = @('release', 'create', "$newVersion")
237237

238238
# Add title parameter
239239
if ($usePRTitleAsReleaseName) {
240240
$prTitle = $pull_request.title
241-
$releaseCreateCommand += @("--title", "$prTitle")
241+
$releaseCreateCommand += @('--title', "$prTitle")
242242
Write-Output "Using PR title as release name: [$prTitle]"
243243
} else {
244-
$releaseCreateCommand += @("--title", "$newVersion")
244+
$releaseCreateCommand += @('--title', "$newVersion")
245245
}
246246

247247
# Add notes parameter
248+
$notes = ''
248249
if ($usePRTitleAsNotesHeading) {
249250
$prTitle = $pull_request.title
250251
$prNumber = $pull_request.number
252+
$notes += "# $prTitle (#$prNumber)`n`n"
253+
}
254+
if ($usePRBodyAsReleaseNotes) {
251255
$prBody = $pull_request.body
252-
$notes = "# $prTitle (#$prNumber)`n`n$prBody"
253-
$releaseCreateCommand += @("--notes", "$notes")
254-
Write-Output 'Using PR title as H1 heading with link and body as release notes'
255-
} elseif ($usePRBodyAsReleaseNotes) {
256-
$prBody = $pull_request.body
257-
$releaseCreateCommand += @("--notes", "$prBody")
258-
Write-Output 'Using PR body as release notes'
256+
$notes += $prBody
257+
}
258+
if (-not [string]::IsNullOrWhiteSpace($notes)) {
259+
$releaseCreateCommand += @('--notes', $notes)
259260
} else {
260261
$releaseCreateCommand += '--generate-notes'
261262
}
262263

263264
# Add remaining parameters
264-
$releaseCreateCommand += @("--target", $prHeadRef, "--prerelease")
265+
$releaseCreateCommand += @('--target', $prHeadRef, '--prerelease')
265266

266-
if ($whatIf) {
267-
Write-Output "WhatIf: $releaseCreateCommand"
268-
} else {
267+
Write-Output "gh $($releaseCreateCommand -join ' ')"
268+
if (-not $whatIf) {
269269
# Execute the command and capture the output
270270
$releaseURL = gh @releaseCreateCommand
271271
if ($LASTEXITCODE -ne 0) {
@@ -285,37 +285,36 @@ if ($createPrerelease -or $createRelease -or $whatIf) {
285285
}
286286
} else {
287287
# Build release creation command with options
288-
$releaseCreateCommand = @("release", "create", "$newVersion")
288+
$releaseCreateCommand = @('release', 'create', "$newVersion")
289289

290290
# Add title parameter
291291
if ($usePRTitleAsReleaseName) {
292292
$prTitle = $pull_request.title
293-
$releaseCreateCommand += @("--title", "$prTitle")
293+
$releaseCreateCommand += @('--title', "$prTitle")
294294
Write-Output "Using PR title as release name: [$prTitle]"
295295
} else {
296-
$releaseCreateCommand += @("--title", "$newVersion")
296+
$releaseCreateCommand += @('--title', "$newVersion")
297297
}
298298

299299
# Add notes parameter
300+
$notes = ''
300301
if ($usePRTitleAsNotesHeading) {
301302
$prTitle = $pull_request.title
302303
$prNumber = $pull_request.number
304+
$notes += "# $prTitle (#$prNumber)`n`n"
305+
}
306+
if ($usePRBodyAsReleaseNotes) {
303307
$prBody = $pull_request.body
304-
$notes = "# $prTitle (#$prNumber)`n`n$prBody"
305-
$releaseCreateCommand += @("--notes", "$notes")
306-
Write-Output 'Using PR title as H1 heading with link and body as release notes'
307-
} elseif ($usePRBodyAsReleaseNotes) {
308-
$prBody = $pull_request.body
309-
$releaseCreateCommand += @("--notes", "$prBody")
310-
Write-Output 'Using PR body as release notes'
308+
$notes += $prBody
309+
}
310+
if (-not [string]::IsNullOrWhiteSpace($notes)) {
311+
$releaseCreateCommand += @('--notes', $notes)
311312
} else {
312313
$releaseCreateCommand += '--generate-notes'
313314
}
314315

315-
if ($whatIf) {
316-
Write-Output "WhatIf: $releaseCreateCommand"
317-
} else {
318-
# Execute the command
316+
Write-Output "gh $($releaseCreateCommand -join ' ')"
317+
if (-not $whatIf) {
319318
gh @releaseCreateCommand
320319
if ($LASTEXITCODE -ne 0) {
321320
Write-Error "Failed to create the release [$newVersion]."

0 commit comments

Comments
 (0)