ado/git/repositories/public/getRepository.ps1

function Get-AdoRepository {
    <#
    .SYNOPSIS
        Get the repository.
 
    .DESCRIPTION
        This function retrieves the repository details as GitRepository object for an Azure DevOps repository through REST API.
 
    .PARAMETER ProjectId
        Mandatory. The unique identifier or name of the project.
 
    .PARAMETER Name
        Mandatory. The name or ID of the repository.
 
    .LINK
        https://learn.microsoft.com/en-us/rest/api/azure/devops/git/repositories/get-repository
 
    .EXAMPLE
        $repo = Get-AdoRepository -ProjectName 'my-project-001' -Name 'my-project-001'
    #>

    [CmdletBinding()]
    [OutputType([pscustomobject])]
    param (
        [Parameter(Mandatory)]
        [Alias('ProjectName')]
        [string]$ProjectId,

        [Parameter(Mandatory)]
        [string]$Name,

        [Parameter(Mandatory = $false)]
        [Alias('Api')]
        [ValidateSet('7.1', '7.2-preview.1')]
        [string]$ApiVersion = '7.1'
    )

    begin {
        Write-Verbose ('Command : {0}' -f $MyInvocation.MyCommand.Name)
        Write-Verbose (' ProjectId : {0}' -f $ProjectId)
        Write-Verbose (' Name : {0}' -f $Name)
        Write-Verbose (' ApiVersion : {0}' -f $ApiVersion)
    }

    process {
        try {
            $ErrorActionPreference = 'Stop'

            if (-not $global:AzDevOpsIsConnected) {
                throw 'Not connected to Azure DevOps. Please connect using Connect-AdoOrganization.'
            }

            $uriFormat = '{0}/{1}/_apis/git/repositories/{2}?api-version={3}'
            $azDevOpsUri = ($uriFormat -f [uri]::new($global:AzDevOpsOrganization), [uri]::EscapeDataString($ProjectId), [uri]::EscapeDataString($Name), $ApiVersion)

            $params = @{
                Method  = 'GET'
                Uri     = $azDevOpsUri
                Headers = $global:AzDevOpsHeaders
            }

            $response = Invoke-RestMethod @params -Verbose:$VerbosePreference

            return $response

        } catch {
            throw $_
        }
    }

    end {
        Write-Verbose ('Exit : {0}' -f $MyInvocation.MyCommand.Name)
    }
}