Private/Get-PDKGithubFileObject.ps1
Function Get-PDKGithubFileObject { <# .SYNOPSIS Get file object of github file .PARAMETER FilePath The content path. .PARAMETER Owner Specifies the owner of the github Repository. .PARAMETER Repository Specifies the target repository name. .EXAMPLE PS C:\> Get-PDKGithubFileObject -FilePath 'Plan\DeathStar.pdf' -Owner 'dark-vador' -Repository 'Sith' .NOTES File Name : Get-PDKGithubFileObject.ps1 Author : Thomas ILLIET (contact@thomas-illiet.fr) Reference : https://developer.github.com/v3/repos/contents/ #> [CmdletBinding()] [OutputType([Object])] Param( [Parameter(Mandatory=$True, Position=0)] [String]$FilePath, [Parameter(Mandatory=$True, Position=1)] [String]$Owner, [Parameter(Mandatory=$True, Position=2)] [String]$Repository ) # +++++++++++++++++++++++++++++ # + Create Request if([string]::IsNullOrEmpty($Script:GithubAuthorization)) { $Params = @{ Uri = "https://api.github.com/repos/$($Owner)/$($Repository)/contents/$FilePath" ErrorAction = "Stop" } } else { $Params = @{ Headers = @{Authorization=$Script:GithubAuthorization} Uri = "https://api.github.com/repos/$($Owner)/$($Repository)/contents/$FilePath" ErrorAction = "Stop" } } Write-Debug "Uri - $($Params.Uri)" # +++++++++++++++++++++++++++++ # + Send Request try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $ContentRequest = Invoke-RestMethod @Params return $ContentRequest } Catch { $ErrorDetails = ConvertFrom-Json -InputObject $_ switch ($ErrorDetails.message) { "Not Found" { Write-Error "The requested File was not found on this Repository" } Default { Write-Error "Unknown Error : $_" } } } } |