Private/ConvertTo-AvmAzureDevOpsDescription.ps1

function ConvertTo-AvmAzureDevOpsDescription {
    <#
    .SYNOPSIS
        Truncates a PR description to fit Azure DevOps's description size limit.

    .DESCRIPTION
        'az repos pr create'/'update' only accept the description as a CLI string argument
        (no file-based option exists), so large Markdown reports must be capped before being
        passed on the command line. When truncated, a note pointing at the pipeline
        artifacts is appended so reviewers know the full report is available elsewhere.

    .PARAMETER Body
        The full Markdown report text.

    .PARAMETER MaxLength
        Maximum description length. Defaults to 4000, comfortably under Azure DevOps's
        actual PR description limit (~4000 characters).

    .OUTPUTS
        String, truncated with a trailing note if it exceeded MaxLength.
    #>

    [CmdletBinding()]
    [OutputType([string])]
    param(
        [Parameter(Mandatory)]
        [AllowEmptyString()]
        [string]$Body,

        [Parameter()]
        [int]$MaxLength = 4000
    )

    if ($Body.Length -le $MaxLength) { return $Body }

    $note   = "`n`n_...truncated — full report available in pipeline artifacts._"
    $budget = $MaxLength - $note.Length
    if ($budget -lt 0) { $budget = 0 }

    return $Body.Substring(0, $budget) + $note
}