diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 306378e..089a75f 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -233,39 +233,39 @@ if ($createPrerelease -or $createRelease -or $whatIf) { } # Build release creation command with options - $releaseCreateCommand = @("release", "create", "$newVersion") + $releaseCreateCommand = @('release', 'create', "$newVersion") # Add title parameter if ($usePRTitleAsReleaseName) { $prTitle = $pull_request.title - $releaseCreateCommand += @("--title", "$prTitle") + $releaseCreateCommand += @('--title', "$prTitle") Write-Output "Using PR title as release name: [$prTitle]" } else { - $releaseCreateCommand += @("--title", "$newVersion") + $releaseCreateCommand += @('--title', "$newVersion") } # Add notes parameter + $notes = '' if ($usePRTitleAsNotesHeading) { $prTitle = $pull_request.title $prNumber = $pull_request.number + $notes += "# $prTitle (#$prNumber)`n`n" + } + if ($usePRBodyAsReleaseNotes) { $prBody = $pull_request.body - $notes = "# $prTitle (#$prNumber)`n`n$prBody" - $releaseCreateCommand += @("--notes", "$notes") - Write-Output 'Using PR title as H1 heading with link and body as release notes' - } elseif ($usePRBodyAsReleaseNotes) { - $prBody = $pull_request.body - $releaseCreateCommand += @("--notes", "$prBody") - Write-Output 'Using PR body as release notes' + $notes += $prBody + } + if (-not [string]::IsNullOrWhiteSpace($notes)) { + $releaseCreateCommand += @('--notes', $notes) } else { $releaseCreateCommand += '--generate-notes' } # Add remaining parameters - $releaseCreateCommand += @("--target", $prHeadRef, "--prerelease") + $releaseCreateCommand += @('--target', $prHeadRef, '--prerelease') - if ($whatIf) { - Write-Output "WhatIf: $releaseCreateCommand" - } else { + Write-Output "gh $($releaseCreateCommand -join ' ')" + if (-not $whatIf) { # Execute the command and capture the output $releaseURL = gh @releaseCreateCommand if ($LASTEXITCODE -ne 0) { @@ -285,37 +285,36 @@ if ($createPrerelease -or $createRelease -or $whatIf) { } } else { # Build release creation command with options - $releaseCreateCommand = @("release", "create", "$newVersion") + $releaseCreateCommand = @('release', 'create', "$newVersion") # Add title parameter if ($usePRTitleAsReleaseName) { $prTitle = $pull_request.title - $releaseCreateCommand += @("--title", "$prTitle") + $releaseCreateCommand += @('--title', "$prTitle") Write-Output "Using PR title as release name: [$prTitle]" } else { - $releaseCreateCommand += @("--title", "$newVersion") + $releaseCreateCommand += @('--title', "$newVersion") } # Add notes parameter + $notes = '' if ($usePRTitleAsNotesHeading) { $prTitle = $pull_request.title $prNumber = $pull_request.number + $notes += "# $prTitle (#$prNumber)`n`n" + } + if ($usePRBodyAsReleaseNotes) { $prBody = $pull_request.body - $notes = "# $prTitle (#$prNumber)`n`n$prBody" - $releaseCreateCommand += @("--notes", "$notes") - Write-Output 'Using PR title as H1 heading with link and body as release notes' - } elseif ($usePRBodyAsReleaseNotes) { - $prBody = $pull_request.body - $releaseCreateCommand += @("--notes", "$prBody") - Write-Output 'Using PR body as release notes' + $notes += $prBody + } + if (-not [string]::IsNullOrWhiteSpace($notes)) { + $releaseCreateCommand += @('--notes', $notes) } else { $releaseCreateCommand += '--generate-notes' } - if ($whatIf) { - Write-Output "WhatIf: $releaseCreateCommand" - } else { - # Execute the command + Write-Output "gh $($releaseCreateCommand -join ' ')" + if (-not $whatIf) { gh @releaseCreateCommand if ($LASTEXITCODE -ne 0) { Write-Error "Failed to create the release [$newVersion]."