|
| 1 | +function Get-ReleaseNotes { |
| 2 | + param ( |
| 3 | + [Parameter(Mandatory=$true)] |
| 4 | + [string]$MarkdownFile |
| 5 | + ) |
| 6 | + |
| 7 | + # Read markdown file content |
| 8 | + $content = Get-Content -Path $MarkdownFile -Raw |
| 9 | + |
| 10 | + # Split content based on headers |
| 11 | + $sections = $content -split "####" |
| 12 | + |
| 13 | + # Output object to store result |
| 14 | + $outputObject = [PSCustomObject]@{ |
| 15 | + Version = $null |
| 16 | + Date = $null |
| 17 | + ReleaseNotes = $null |
| 18 | + } |
| 19 | + |
| 20 | + # Check if we have at least 3 sections (1. Before the header, 2. Header, 3. Release notes) |
| 21 | + if ($sections.Count -ge 3) { |
| 22 | + $header = $sections[1].Trim() |
| 23 | + $releaseNotes = $sections[2].Trim() |
| 24 | + |
| 25 | + # Extract version and date from the header |
| 26 | + $headerParts = $header -split " ", 2 |
| 27 | + if ($headerParts.Count -eq 2) { |
| 28 | + $outputObject.Version = $headerParts[0] |
| 29 | + $outputObject.Date = $headerParts[1] |
| 30 | + } |
| 31 | + |
| 32 | + $outputObject.ReleaseNotes = $releaseNotes |
| 33 | + } |
| 34 | + |
| 35 | + # Return the output object |
| 36 | + return $outputObject |
| 37 | +} |
| 38 | + |
| 39 | +# Call function example: |
| 40 | +#$result = Get-ReleaseNotes -MarkdownFile "$PSScriptRoot\RELEASE_NOTES.md" |
| 41 | +#Write-Output "Version: $($result.Version)" |
| 42 | +#Write-Output "Date: $($result.Date)" |
| 43 | +#Write-Output "Release Notes:" |
| 44 | +#Write-Output $result.ReleaseNotes |
0 commit comments