Public/ReleaseNotes/ExportMarkDown/Export-MarkDownSection.ps1
function Export-MarkDownSection { <# .SYNOPSIS Creates a single MD section for release notes .PARAMETER ExportData Export data prepared by ConvertTo-ExportData. .PARAMETER File Filename for the exported data to be saved to. .PARAMETER Header Flag, whether to always use the same filename. If Path is a folder, uses constant string for the new file. .PARAMETER SubHeaders List of items with properties: - type = work item type - name = human friendly name .PARAMETER State Work item state to filter work items by. .PARAMETER ProgressPreference Determines how PowerShell responds to progress updates generated by a script, cmdlet, or provider, such as the progress bars generated by the Write-Progress cmdlet. #> [CmdletBinding(DefaultParameterSetName = 'List')] param( [PSTypeName('PSTypeNames.AzureDevOpsApi.ExportData')] [Parameter(Mandatory, Position = 1)] [Alias('Data')] $ExportData, $File = '.\output.md', [string] $Header = 'Header', $SubHeaders = @(), $State = 'closed', [System.Management.Automation.ActionPreference] $ProgressPreference = $PSCmdlet.GetVariableValue('ProgressPreference') ) begin { $activity = "Writing ${Header}" Write-Progress -Activity $activity } process { Add-Content -Path $file "" Add-Content -Path $file "\newpage" $headerText = "## <span class=`"underline`">{0}</span>" -f $Header Add-Content -Path $File $headerText foreach ($sub in $SubHeaders) { Write-Progress -Activity $activity -CurrentOperation $sub.name $subItems = @( $ExportData.WorkItems ` | Where-Object { $_.WorkItemType -ilike $sub.type -and $_.State -ilike $State } ` | Sort-Object -Property WorkItemId ) if ($subItems.Length -eq 0) { continue } Add-Content "" -Path $file $subheaderText = "### {0}" -f $sub.name Add-Content -Path $File $subheaderText for ($i = 0; $i -lt $subItems.Length; $i++) { $curItem = $subItems[$i] $itemText = "{0}. [#{1}]({2}) - {3}" -f ( ($i + 1), $curItem.WorkItemId, $curItem.PortalUrl, $curItem.Title ) Add-Content -Path $file $itemText } } } end { Write-Progress -Activity $activity -Completed } } |