Public/ReleaseNotes/Export-ReleaseNotesFromTimePeriodToMarkDown.ps1

function Export-ReleaseNotesFromTimePeriodToMarkDown {

    <#
        .SYNOPSIS
            Runs compilation of release notes data from Git based project and formats it in MarkDown.

        .PARAMETER CollectionUri
            Url for project collection on Azure DevOps server instance.
            Can be ommitted if $CollectionUri was previously accessed via this API.
            If not specified, $global:AzureDevOpsApi_CollectionUri (set by Set-AzureDevopsVariables) is used.

        .PARAMETER Project
            Project name, identifier, full project URI, or object with any one
            these properties.
            Can be ommitted if $Project was previously accessed via this API (will be extracted from the $ArtifactUri).
            If not specified, $global:AzureDevOpsApi_Project (set by Set-AzureDevopsVariables) is used.

        .PARAMETER DateFrom
            Starting date for the considered work items.

        .PARAMETER DateTo
            Ending date for the considered work items.

        .PARAMETER AsOf
            Gets the Work Items as they were at this date and time.

        .PARAMETER PassThru
            Flag, whether return the generated file.

        .PARAMETER Environment
            Environment name.

        .PARAMETER UseConstantFileName
            Flag, whether to use constant file name.
            If $Path is a directory, the file will be named "ReleaseNotes.xlsx"
            Ignored if $Path is a filename.

        .PARAMETER Path
            Path or filename for the exported data to be saved to.
            If not specified, the file will be saved to the current directory.
            If points to a directory and $UseConstantFileName is specified,
            the file will be named "ReleaseNotes.xlsx", otherwise the filename
            will be "ReleaseNotes_$Project_$CreatedOnDateTime.xlsx".

        .PARAMETER TimeZone
            All times from AzureDevOps API are in UTC.
            Parameter determines the time zone all date times will be converted to.

            Uses .net TimeZoneInfo class to resolve and calculate the date times.

            Possible values are:
            IANA style zone ids, f.e. "Europe/Bratislava"
            Windows style zone ids, f.e. "Central Europe Standard Time"

            Default value is "Central Europe Standard Time".

        .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()]
    param(
        [AllowNull()]
        [AllowEmptyString()]
        $CollectionUri,

        [AllowNull()]
        [AllowEmptyString()]
        $Project,

        [Alias('FromDate', 'From')]
        [Nullable[DateTime]] $DateFrom,

        [Alias('ToDate', 'To')]
        [Nullable[DateTime]] $DateTo,

        [Nullable[DateTime]] $AsOf,

        [switch] $PassThru,

        [switch] $UseConstantFileName,

        $Path = '.\',

        [string] $TimeZone = 'UTC',

        $Environment = '',

        [System.Management.Automation.ActionPreference] $ProgressPreference = $PSCmdlet.GetVariableValue('ProgressPreference')
    )

    # Show start message
    Show-Host -ForegroundColor Cyan -Object 'Release list export started'

    # Report back provided parameters
    Show-Host -ForegroundColor Magenta -Object 'Provided parameters'

    # Show input parameters
    Show-Parameters -Parameters $MyInvocation.BoundParameters

    # Gather the release notes data by time period
    $data = Get-ReleaseNotesDataFromTimePeriod `
       -Collection $CollectionUri `
       -Project $Project `
       -DateFrom $DateFrom `
       -DateTo $DateTo `
       -AsOf $AsOf `
       -ByUser $ByUser

    # Prepare the data for export
    Show-Host -ForegroundColor Magenta -Object 'Preparing Work Item Data for export...'
    $exportData = ConvertTo-ExportData `
        -ItemsTable $data `
        -Collection $CollectionUri `
        -Project $Project `
        -DateFrom $DateFrom `
        -DateTo $DateTo `
        -AsOf $AsOf `
        -ByUser $ByUser

    # Export the data
    Show-Host -ForegroundColor Magenta -Object 'Exporting Data...'
    $outputFile = Export-MarkDown `
        -ExportData $exportData `
        -Path $Path `
        -TimeZone $TimeZone `
        -UseConstantFileName:$UseConstantFileName `
        -Environment $Environment `
        -PassThru:$true

    # Report the file path
    ([PSCustomObject] @{ ExportedTo = $outputFile.FullName }) | Format-List | Out-Host

    # Return the output file
    if ($PassThru) {
        return $outputFile
    }
}