Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete support for Releases API #177

Merged
merged 27 commits into from
Jul 20, 2020
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7e8a6fc
WIP
HowardWolosky May 21, 2020
12645d5
Working asset download
HowardWolosky May 22, 2020
2a340b2
Adding New/Set GitHubAsset
HowardWolosky May 22, 2020
e0e52cb
Fixing high impact stuff
HowardWolosky May 22, 2020
5fc512d
Adding verbose log message for the move-item
HowardWolosky May 22, 2020
3b62677
Minor fixes
HowardWolosky May 22, 2020
9b4c84e
Remove some unnecessary aliases
HowardWolosky May 22, 2020
f5bc7ed
minor updates
HowardWolosky May 22, 2020
daf4ac3
Fixing Static Analysis issues
HowardWolosky Jun 4, 2020
e16763f
fix casing
HowardWolosky Jun 4, 2020
fd02821
Working on tests
HowardWolosky Jun 4, 2020
35fe1b1
Applying CR feedback and adding additional tests
HowardWolosky Jun 7, 2020
b5c57a6
Applying more CR feedback
HowardWolosky Jun 8, 2020
c9235d5
Update the tests and functions to accomodate latest master changes
HowardWolosky Jun 18, 2020
8cb9157
Update the WhatIf/ShouldProcess handling per #254
HowardWolosky Jul 7, 2020
75dc009
Support UploadUrl from pipeline input and better handling of multiple…
HowardWolosky Jul 7, 2020
2bde468
Fix bad merge
HowardWolosky Jul 8, 2020
48ffb06
Update spelling of committish
HowardWolosky Jul 8, 2020
677672f
Additional PR feedback
HowardWolosky Jul 8, 2020
f6253c0
Add formatting for GitHub.Release and GitHub.ReleaseAsset
HowardWolosky Jul 9, 2020
5471ef6
Final updates and expansive UT improvements for pipelining
HowardWolosky Jul 9, 2020
5314ad1
Add missing USAGE.md entries
HowardWolosky Jul 9, 2020
71fb672
Fix positional binding, increase code cov by adding ContentType to a …
HowardWolosky Jul 9, 2020
de0e4bc
Add additional default content types, improve formatting
HowardWolosky Jul 9, 2020
9dd225d
Remove default parameter set to fix PS7 issues
HowardWolosky Jul 10, 2020
7abb1d6
Trying to fix test for linux/mac
HowardWolosky Jul 18, 2020
15de9b0
Trying to fix Get-GitHubReleaseAsset.Verifying a zip file test on Lin…
HowardWolosky Jul 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support UploadUrl from pipeline input and better handling of multiple…
… paths on pipeline
HowardWolosky committed Jul 19, 2020
commit 75dc00936e51eac7ec21bc228c094ae6b5921532
113 changes: 63 additions & 50 deletions GitHubReleases.ps1
Original file line number Diff line number Diff line change
@@ -892,7 +892,7 @@ filter Get-GitHubReleaseAsset
}
}

filter New-GitHubReleaseAsset
function New-GitHubReleaseAsset
{
<#
.SYNOPSIS
@@ -988,6 +988,9 @@ filter New-GitHubReleaseAsset
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='Uri')]
[Parameter(
ValueFromPipelineByPropertyName,
ParameterSetName='UploadUrl')]
[Alias('RepositoryUrl')]
[string] $Uri,

@@ -1004,6 +1007,7 @@ filter New-GitHubReleaseAsset

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName,
ParameterSetName='UploadUrl')]
[string] $UploadUrl,

@@ -1024,69 +1028,77 @@ filter New-GitHubReleaseAsset
[switch] $NoStatus
)

Write-InvocationLog

$telemetryProperties = @{
'ProvidedUploadUrl' = (-not [String]::IsNullOrWhiteSpace($UploadUrl))
'ProvidedLabel' = (-not [String]::IsNullOrWhiteSpace($Label))
'ProvidedContentType' = (-not [String]::IsNullOrWhiteSpace($ContentType))
}

# If UploadUrl wasn't provided, we'll need to query for it first.
if ($PSCmdlet.ParameterSetName -in ('Elements', 'Uri'))
begin
{
$elements = Resolve-RepositoryElements
$OwnerName = $elements.ownerName
$RepositoryName = $elements.repositoryName
Write-InvocationLog

$telemetryProperties['OwnerName'] = (Get-PiiSafeString -PlainText $OwnerName)
$telemetryProperties['RepositoryName'] = (Get-PiiSafeString -PlainText $RepositoryName)
$telemetryProperties = @{
'ProvidedUploadUrl' = (-not [String]::IsNullOrWhiteSpace($UploadUrl))
'ProvidedLabel' = (-not [String]::IsNullOrWhiteSpace($Label))
'ProvidedContentType' = (-not [String]::IsNullOrWhiteSpace($ContentType))
}

$params = @{
'OwnerName' = $OwnerName
'RepositoryName' = $RepositoryName
'Release' = $Release
'AccessToken' = $AccessToken
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
# If UploadUrl wasn't provided, we'll need to query for it first.
if ($PSCmdlet.ParameterSetName -in ('Elements', 'Uri'))
{
$elements = Resolve-RepositoryElements
$OwnerName = $elements.ownerName
$RepositoryName = $elements.repositoryName

$telemetryProperties['OwnerName'] = (Get-PiiSafeString -PlainText $OwnerName)
$telemetryProperties['RepositoryName'] = (Get-PiiSafeString -PlainText $RepositoryName)

$params = @{
'OwnerName' = $OwnerName
'RepositoryName' = $RepositoryName
'Release' = $Release
'AccessToken' = $AccessToken
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}

$releaseInfo = Get-GitHubRelease @params
$UploadUrl = $releaseInfo.upload_url
}

$releaseInfo = Get-GitHubRelease @params
$UploadUrl = $releaseInfo.upload_url
# Remove the '{name,label}' from the Url if it's there
if ($UploadUrl -match '(.*){')
{
$UploadUrl = $Matches[1]
}
}

# Remove the '{name,label}' from the Url if it's there
if ($UploadUrl -match '(.*){')
process
{
$UploadUrl = $Matches[1]
}
$Path = Resolve-UnverifiedPath -Path $Path
$file = Get-Item -Path $Path
$fileName = $file.Name
$fileNameEncoded = [Uri]::EscapeDataString($fileName)
$queryParams = @("name=$fileNameEncoded")

$Path = Resolve-UnverifiedPath -Path $Path
$file = Get-Item -Path $Path
$fileName = $file.Name
$fileNameEncoded = [Uri]::EscapeDataString($fileName)
$queryParams = @("name=$fileNameEncoded")
$labelEncoded = [Uri]::EscapeDataString($Label)
if (-not [String]::IsNullOrWhiteSpace($Label)) { $queryParams += "label=$labelEncoded" }

$labelEncoded = [Uri]::EscapeDataString($Label)
if (-not [String]::IsNullOrWhiteSpace($Label)) { $queryParams += "label=$labelEncoded" }
if (-not $PSCmdlet.ShouldProcess($Path, "Create new GitHub Release Asset"))
{
return
}

if (-not $PSCmdlet.ShouldProcess($Path, "Create new GitHub Release Asset"))
{
return
}
$params = @{
'UriFragment' = $UploadUrl + '?' + ($queryParams -join '&')
'Method' = 'Post'
'Description' = "Uploading $fileName as a release asset"
'InFile' = $Path
'ContentType' = $ContentType
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}

$params = @{
'UriFragment' = $UploadUrl + '?' + ($queryParams -join '&')
'Method' = 'Post'
'Description' = "Uploading $fileName as a release asset"
'InFile' = $Path
'ContentType' = $ContentType
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
return (Invoke-GHRestMethod @params | Add-GitHubReleaseAssetAdditionalProperties)
}

return (Invoke-GHRestMethod @params | Add-GitHubReleaseAssetAdditionalProperties)
end {}
}

filter Set-GitHubReleaseAsset
@@ -1396,6 +1408,7 @@ filter Add-GitHubReleaseAdditionalProperties
}

Add-Member -InputObject $item -Name 'ReleaseId' -Value $item.id -MemberType NoteProperty -Force
Add-Member -InputObject $item -Name 'UploadUrl' -Value $item.upload_url -MemberType NoteProperty -Force

if ($null -ne $item.author)
{