Public/Get-PDKGituhbRelease.ps1

Function Get-PDKGituhbRelease {
    [CmdletBinding(DefaultParameterSetName='All')]
    Param (
        [Parameter(Mandatory=$False, ParameterSetName='Name', Position=0)]
        [String]$Name,
        [Parameter(Mandatory=$False,  ParameterSetName='Latest', Position=1)]
        [Switch]$Latest=$False,
        [Parameter(Mandatory=$False, Position=2)]
        [ValidateSet('Basic', 'FullDetailed')]
        [String]$Format='Basic',
        [Parameter(Mandatory=$True, Position=3)]
        [String]$Owner,
        [Parameter(Mandatory=$True, Position=4)]
        [String]$Repository
    )

    Write-Debug $PSCmdlet.ParameterSetName
    # +++++++++++++++++++++++++++++
    # + Create Request
    switch ($PSCmdlet.ParameterSetName) {
        # ++++++++++++++++++++++++
        # + Get all Release
        All {
            $Params = @{
                Headers     = @{Authorization=$Script:GithubAuthorization}
                Uri         = "https://api.github.com/repos/$Owner/$Repository/releases"
                ErrorAction = "Stop"
            }
        }
        # ++++++++++++++++++++++++
        # + Get latest Release
        Latest {
            $Params = @{
                Headers     = @{Authorization=$Script:GithubAuthorization}
                Uri         = "https://api.github.com/repos/$Owner/$Repository/releases/latest"
                ErrorAction = "Stop"
            }
        }
        # ++++++++++++++++++++++++
        # + Get Release by name
        Name {
            $Params = @{
                Headers     = @{Authorization=$Script:GithubAuthorization}
                Uri         = "https://api.github.com/repos/$Owner/$Repository/releases/tags/$Name"
                ErrorAction = "Stop"
            }
        }
    }

    # +++++++++++++++++++++++++++++
    # + Send Request
    try {
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        $ReleaseObject = Invoke-RestMethod @Params
    } Catch {
        $ErrorDetails = ConvertFrom-Json -InputObject $_
        switch ($ErrorDetails.errors.code) {
            "already_exists" { Write-Error "Release branch already exists" }
            Default          { Write-Error "Unknown Error : $_" }
        }
    }

    # +++++++++++++++++++++++++++++
    # + Format
    if($Format -eq 'Basic') {
        $ReleaseFormat = $ReleaseObject | Select-Object tag_name, target_commitish, created_at, html_url
    } else {
        $ReleaseFormat = $ReleaseObject
    }
    return $ReleaseFormat
}