diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 6bee8221..3f3fbb06 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -46,6 +46,7 @@ filter Get-GitHubAssignee GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -159,6 +160,7 @@ filter Test-GitHubAssignee GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -303,6 +305,7 @@ function Add-GitHubAssignee GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -481,6 +484,7 @@ function Remove-GitHubAssignee GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index 41e5b100..502a785d 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -58,6 +58,7 @@ filter Get-GitHubRepositoryBranch GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index 53397540..85b290f8 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -73,6 +73,7 @@ GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 50b6a3d7..a8dcdbd9 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -341,7 +341,7 @@ function Invoke-GHRestMethod $finalResult = $finalResult } - if (-not (Get-GitHubConfiguration -Name DisableSmarterObjects)) + if ((-not $Save) -and (-not (Get-GitHubConfiguration -Name DisableSmarterObjects))) { # In the case of getting raw content from the repo, we'll end up with a large object/byte # array which isn't convertible to a smarter object, but by _trying_ we'll end up wasting diff --git a/GitHubEvents.ps1 b/GitHubEvents.ps1 index 000574af..2dc597db 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -60,6 +60,7 @@ filter Get-GitHubEvent GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index 0542581b..48ec9447 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -81,6 +81,7 @@ filter Get-GitHubIssueComment GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -346,6 +347,7 @@ filter New-GitHubIssueComment GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -490,6 +492,7 @@ filter Set-GitHubIssueComment GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -621,6 +624,7 @@ filter Remove-GitHubIssueComment GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 705a9da6..afd90bcf 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -130,6 +130,7 @@ filter Get-GitHubIssue GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -434,6 +435,7 @@ filter Get-GitHubIssueTimeline GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -573,6 +575,7 @@ filter New-GitHubIssue GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -742,6 +745,7 @@ filter Set-GitHubIssue GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -893,6 +897,7 @@ filter Lock-GitHubIssue GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE @@ -1024,6 +1029,7 @@ filter Unlock-GitHubIssue GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index dd1391ac..22cf446f 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -65,6 +65,7 @@ filter Get-GitHubLabel GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -253,6 +254,7 @@ filter New-GitHubLabel GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -395,6 +397,7 @@ filter Remove-GitHubLabel GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE @@ -553,6 +556,7 @@ filter Set-GitHubLabel GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -700,6 +704,7 @@ filter Initialize-GitHubLabel GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE @@ -840,6 +845,7 @@ function Add-GitHubIssueLabel GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1001,6 +1007,7 @@ function Set-GitHubIssueLabel GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1193,6 +1200,7 @@ filter Remove-GitHubIssueLabel GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index d2f2dc73..7326bf5e 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -69,6 +69,7 @@ filter Get-GitHubMilestone GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -272,6 +273,7 @@ filter New-GitHubMilestone GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -454,6 +456,7 @@ filter Set-GitHubMilestone GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -635,6 +638,7 @@ filter Remove-GitHubMilestone GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index 20ecb3ee..a90a0a41 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -250,6 +250,7 @@ filter Get-GitHubLicense GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -488,6 +489,7 @@ filter Get-GitHubCodeOfConduct GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index c96dc30f..87566375 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -64,6 +64,7 @@ filter Get-GitHubProject GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -277,6 +278,7 @@ filter New-GitHubProject GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -457,6 +459,7 @@ filter Set-GitHubProject GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -585,6 +588,7 @@ filter Remove-GitHubProject GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 0eeb5ee4..50b87fea 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -78,6 +78,7 @@ filter Get-GitHubPullRequest GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -274,6 +275,7 @@ filter New-GitHubPullRequest GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 034e2ca7..4379384a 100644 --- a/GitHubReleases.ps1 +++ b/GitHubReleases.ps1 @@ -3,6 +3,7 @@ @{ GitHubReleaseTypeName = 'GitHub.Release' + GitHubReleaseAssetTypeName = 'GitHub.ReleaseAsset' }.GetEnumerator() | ForEach-Object { Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value } @@ -67,6 +68,7 @@ filter Get-GitHubRelease GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -279,6 +281,25 @@ filter New-GitHubRelease the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.ReleaseAsset + GitHub.Repository + + .OUTPUTS + GitHub.Release + .EXAMPLE New-GitHubRelease -OwnerName microsoft -RepositoryName PowerShellForGitHub -TagName 0.12.0 @@ -291,6 +312,7 @@ filter New-GitHubRelease [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubReleaseTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -352,22 +374,17 @@ filter New-GitHubRelease if ($PSBoundParameters.ContainsKey('PreRelease')) { $hashBody['prerelease'] = $PreRelease.ToBool() } $params = @{ - 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases" + 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases" 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Post' - 'Description' = "Creating release at $TagName" + 'Description' = "Creating release at $TagName" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - $result = Invoke-GHRestMethod @params - - # Add additional property to ease pipelining - Add-Member -InputObject $result -Name 'ReleaseId' -Value $result.id -MemberType NoteProperty -Force - - return $result + return (Invoke-GHRestMethod @params | Add-GitHubReleaseAdditionalProperties) } filter Set-GitHubRelease @@ -427,6 +444,25 @@ filter Set-GitHubRelease the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.ReleaseAsset + GitHub.Repository + + .OUTPUTS + GitHub.Release + .EXAMPLE Set-GitHubRelease -OwnerName microsoft -RepositoryName PowerShellForGitHub -TagName 0.12.0 -Body 'Adds core support for Projects' @@ -436,6 +472,7 @@ filter Set-GitHubRelease [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubReleaseTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -501,22 +538,17 @@ filter Set-GitHubRelease if ($PSBoundParameters.ContainsKey('PreRelease')) { $hashBody['prerelease'] = $PreRelease.ToBool() } $params = @{ - 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/$Release" + 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/$Release" 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Patch' - 'Description' = "Creating release at $TagName" + 'Description' = "Creating release at $TagName" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - $result = Invoke-GHRestMethod @params - - # Add additional property to ease pipelining - Add-Member -InputObject $result -Name 'ReleaseId' -Value $result.id -MemberType NoteProperty -Force - - return $result + return (Invoke-GHRestMethod @params | Add-GitHubReleaseAdditionalProperties) } filter Remove-GitHubRelease @@ -556,6 +588,22 @@ filter Remove-GitHubRelease the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.ReleaseAsset + GitHub.Repository + .EXAMPLE Remove-GitHubRelease -OwnerName microsoft -RepositoryName PowerShellForGitHub -Release 1234567890 @@ -584,7 +632,7 @@ filter Remove-GitHubRelease Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri')] - [Alias('ReositoryUrl')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter( @@ -610,9 +658,9 @@ filter Remove-GitHubRelease } $params = @{ - 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/$Release" + 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/$Release" 'Method' = 'Delete' - 'Description' = "Deleting release $Release" + 'Description' = "Deleting release $Release" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -671,6 +719,25 @@ filter Get-GitHubReleaseAsset the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.ReleaseAsset + GitHub.Repository + + .OUTPUTS + GitHub.ReleaseAsset + .EXAMPLE Get-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Release 1234567890 @@ -685,6 +752,7 @@ filter Get-GitHubReleaseAsset [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements-List')] + [OutputType({$script:GitHubReleaseAssetTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( @@ -796,9 +864,9 @@ filter Get-GitHubReleaseAsset } $params = @{ - 'UriFragment' = $uriFragment + 'UriFragment' = $uriFragment 'Method' = 'Get' - 'Description' = $description + 'Description' = $description 'AcceptHeader' = $acceptHeader 'Save' = $shouldSave 'AccessToken' = $AccessToken @@ -816,7 +884,7 @@ filter Get-GitHubReleaseAsset } else { - return $result + return ($result | Add-GitHubReleaseAssetAdditionalProperties) } } @@ -871,6 +939,25 @@ filter New-GitHubReleaseAsset the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.ReleaseAsset + GitHub.Repository + + .OUTPUTS + GitHub.ReleaseAsset + .EXAMPLE New-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -TagName 0.12.0 @@ -884,6 +971,7 @@ filter New-GitHubReleaseAsset [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubReleaseAssetTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( @@ -917,9 +1005,11 @@ filter New-GitHubReleaseAsset [string] $UploadUrl, [Parameter( - Mandatory + Mandatory, ValueFromPipeline)] - [ValidateScript({if (Test-Path -Path $_ -PathType Leaf) { $true } else { throw "$_ does not exist or is inaccessible." }})] + [ValidateScript( + {if (Test-Path -Path $_ -PathType Leaf) { $true} + else { throw "$_ does not exist or is inaccessible." }})] [string] $Path, [string] $Label, @@ -949,7 +1039,15 @@ filter New-GitHubReleaseAsset $telemetryProperties['OwnerName'] = (Get-PiiSafeString -PlainText $OwnerName) $telemetryProperties['RepositoryName'] = (Get-PiiSafeString -PlainText $RepositoryName) - $releaseInfo = Get-GitHubRelease -OwnerName $OwnerName -RepositoryName $RepositoryName -Release $Release -AccessToken:$AccessToken -NoStatus:$NoStatus + $params = @{ + 'OwnerName' = $OwnerName + 'RepositoryName' = $RepositoryName + 'Release' = $Release + 'AccessToken' = $AccessToken + 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) + } + + $releaseInfo = Get-GitHubRelease @params $UploadUrl = $releaseInfo.upload_url } @@ -969,9 +1067,9 @@ filter New-GitHubReleaseAsset if (-not [String]::IsNullOrWhiteSpace($Label)) { $queryParams += "label=$labelEncoded" } $params = @{ - 'UriFragment' = $UploadUrl + '?' + ($queryParams -join '&') + 'UriFragment' = $UploadUrl + '?' + ($queryParams -join '&') 'Method' = 'Post' - 'Description' = "Uploading $fileName as a release asset" + 'Description' = "Uploading $fileName as a release asset" 'InFile' = $Path 'ContentType' = $ContentType 'AccessToken' = $AccessToken @@ -980,7 +1078,7 @@ filter New-GitHubReleaseAsset 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubReleaseAssetAdditionalProperties) } filter Set-GitHubReleaseAsset @@ -1026,6 +1124,25 @@ filter Set-GitHubReleaseAsset the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.ReleaseAsset + GitHub.Repository + + .OUTPUTS + GitHub.ReleaseAsset + .EXAMPLE Set-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Asset 123456 -Name bar.zip @@ -1037,6 +1154,7 @@ filter Set-GitHubReleaseAsset [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] + [OutputType({$script:GitHubReleaseAssetTypeName})] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( @@ -1086,17 +1204,17 @@ filter Set-GitHubReleaseAsset if (-not [String]::IsNullOrWhiteSpace($Label)) { $hashBody['label'] = $Label } $params = @{ - 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/assets/$Asset" + 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/assets/$Asset" 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Patch' - 'Description' = "Editing asset $Asset" + 'Description' = "Editing asset $Asset" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubReleaseAssetAdditionalProperties) } filter Remove-GitHubReleaseAsset @@ -1136,6 +1254,22 @@ filter Remove-GitHubReleaseAsset the background, enabling the command prompt to provide status information. If not supplied here, the DefaultNoStatus configuration property value will be used. + .INPUTS + GitHub.Branch + GitHub.Content + GitHub.Event + GitHub.Issue + GitHub.IssueComment + GitHub.Label + GitHub.Milestone + GitHub.PullRequest + GitHub.Project + GitHub.ProjectCard + GitHub.ProjectColumn + GitHub.Release + GitHub.ReleaseAsset + GitHub.Repository + .EXAMPLE Remove-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Asset 1234567890 @@ -1187,9 +1321,9 @@ filter Remove-GitHubReleaseAsset } $params = @{ - 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/assets/$Asset" + 'UriFragment' = "/repos/$OwnerName/$RepositoryName/releases/assets/$Asset" 'Method' = 'Delete' - 'Description' = "Deleting asset $Asset" + 'Description' = "Deleting asset $Asset" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties @@ -1258,3 +1392,57 @@ filter Add-GitHubReleaseAdditionalProperties Write-Output $item } } + +filter Add-GitHubReleaseAssetAdditionalProperties +{ +<# + .SYNOPSIS + Adds type name and additional properties to ease pipelining to GitHub Release Asset objects. + + .PARAMETER InputObject + The GitHub object to add additional properties to. + + .PARAMETER TypeName + The type that should be assigned to the object. + + .INPUTS + [PSCustomObject] + + .OUTPUTS + GitHub.ReleaseAsset +#> + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="Internal helper that is definitely adding more than one property.")] + param( + [Parameter( + Mandatory, + ValueFromPipeline)] + [AllowNull()] + [AllowEmptyCollection()] + [PSCustomObject[]] $InputObject, + + [ValidateNotNullOrEmpty()] + [string] $TypeName = $script:GitHubReleaseAssetTypeName + ) + + foreach ($item in $InputObject) + { + $item.PSObject.TypeNames.Insert(0, $TypeName) + + if (-not (Get-GitHubConfiguration -Name DisablePipelineSupport)) + { + $elements = Split-GitHubUri -Uri $item.url + $repositoryUrl = Join-GitHubUri @elements + Add-Member -InputObject $item -Name 'RepositoryUrl' -Value $repositoryUrl -MemberType NoteProperty -Force + + Add-Member -InputObject $item -Name 'AssetId' -Value $item.id -MemberType NoteProperty -Force + + if ($null -ne $item.uploader) + { + $null = Add-GitHubUserAdditionalProperties -InputObject $item.uploader + } + } + + Write-Output $item + } +} diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 6a3fbc89..e198ef29 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -110,6 +110,7 @@ filter New-GitHubRepository GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -450,6 +451,7 @@ filter Remove-GitHubRepository GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE @@ -617,6 +619,7 @@ filter Get-GitHubRepository GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -942,6 +945,7 @@ filter Rename-GitHubRepository GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1124,6 +1128,7 @@ filter Set-GitHubRepository GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1309,6 +1314,7 @@ filter Get-GitHubRepositoryTopic GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1425,6 +1431,7 @@ function Set-GitHubRepositoryTopic GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1613,6 +1620,7 @@ filter Get-GitHubRepositoryContributor GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1766,6 +1774,7 @@ filter Get-GitHubRepositoryCollaborator GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1885,6 +1894,7 @@ filter Get-GitHubRepositoryLanguage GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1994,6 +2004,7 @@ filter Get-GitHubRepositoryTag GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -2109,6 +2120,7 @@ filter Move-GitHubRepositoryOwnership GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index 23cc63ae..18a3ca31 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -52,6 +52,7 @@ filter Get-GitHubRepositoryFork GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -170,6 +171,7 @@ filter New-GitHubRepositoryFork GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index 0d32c21e..606b64d6 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -58,6 +58,7 @@ filter Get-GitHubReferrerTraffic GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -172,6 +173,7 @@ filter Get-GitHubPathTraffic GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -293,6 +295,7 @@ filter Get-GitHubViewTraffic GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -418,6 +421,7 @@ filter Get-GitHubCloneTraffic GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index 44c94399..07d38454 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -62,6 +62,7 @@ filter Get-GitHubTeam GitHub.ProjectColumn GitHub.Reaction GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.Team @@ -201,6 +202,7 @@ filter Get-GitHubTeamMember GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.Team diff --git a/Tests/GitHubReleases.tests.ps1 b/Tests/GitHubReleases.tests.ps1 index 0337e213..b81bb384 100644 --- a/Tests/GitHubReleases.tests.ps1 +++ b/Tests/GitHubReleases.tests.ps1 @@ -18,289 +18,308 @@ $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent try { Describe 'Getting releases from repository' { - $releases = @(Get-GitHubRelease -OwnerName $script:dotNetCoreOwnerName -RepositoryName $script:dotNetCoreRepositoryName) + Context 'Common test state' { + BeforeAll { + $dotNetOwnerName = "dotnet" + $repositoryName = "core" - Context 'When getting all releases' { - It 'Should return multiple releases' { - $releases.Count | Should -BeGreaterThan 1 + $releases = @(Get-GitHubRelease -OwnerName $dotNetOwnerName -RepositoryName $repositoryName) } - It 'Should have expected type and additional properties' { - $releases[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' - $releases[0].html_url.StartsWith($releases[0].RepositoryUrl) | Should -BeTrue - $releases[0].id | Should -Be $releases[0].ReleaseId + Context 'When getting all releases' { + It 'Should return multiple releases' { + $releases.Count | Should -BeGreaterThan 1 + } + + It 'Should have expected type and additional properties' { + $releases[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $releases[0].html_url.StartsWith($releases[0].RepositoryUrl) | Should -BeTrue + $releases[0].id | Should -Be $releases[0].ReleaseId + } } - } - Context 'When getting the latest releases' { - $latest = @(Get-GitHubRelease -OwnerName $script:dotNetCoreOwnerName -RepositoryName $script:dotNetCoreRepositoryName -Latest) + Context 'When getting the latest releases' { + $latest = @(Get-GitHubRelease -OwnerName $dotNetOwnerName -RepositoryName $repositoryName -Latest) - It 'Should return one value' { - $latest.Count | Should -Be 1 - } + It 'Should return one value' { + $latest.Count | Should -Be 1 + } - It 'Should return the first release from the full releases list' { - $latest[0].url | Should -Be $releases[0].url - $latest[0].name | Should -Be $releases[0].name - } - } + It 'Should return the first release from the full releases list' { + $latest[0].url | Should -Be $releases[0].url + $latest[0].name | Should -Be $releases[0].name + } - It 'Should have expected type and additional properties' { - $latest[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' - $latest[0].html_url.StartsWith($latest[0].RepositoryUrl) | Should -BeTrue - $latest[0].id | Should -Be $latest[0].ReleaseId + It 'Should have expected type and additional properties' { + $latest[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $latest[0].html_url.StartsWith($latest[0].RepositoryUrl) | Should -BeTrue + $latest[0].id | Should -Be $latest[0].ReleaseId + } } - } - Context 'When getting the latest releases via the pipeline' { - $latest = @(Get-GitHubRepository -OwnerName $ownerName -RepositoryName $repositoryName | - Get-GitHubRelease -Latest) + Context 'When getting the latest releases via the pipeline' { + $latest = @(Get-GitHubRepository -OwnerName $dotNetOwnerName -RepositoryName $repositoryName | + Get-GitHubRelease -Latest) - It 'Should return one value' { - $latest.Count | Should -Be 1 - } - } + It 'Should return one value' { + $latest.Count | Should -Be 1 + } - It 'Should return the first release from the full releases list' { - $latest[0].url | Should -Be $releases[0].url - $latest[0].name | Should -Be $releases[0].name - } + It 'Should return the first release from the full releases list' { + $latest[0].url | Should -Be $releases[0].url + $latest[0].name | Should -Be $releases[0].name + } - It 'Should have expected type and additional properties' { - $latest[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' - $latest[0].html_url.StartsWith($latest[0].RepositoryUrl) | Should -BeTrue - $latest[0].id | Should -Be $latest[0].ReleaseId - } + It 'Should have expected type and additional properties' { + $latest[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $latest[0].html_url.StartsWith($latest[0].RepositoryUrl) | Should -BeTrue + $latest[0].id | Should -Be $latest[0].ReleaseId + } - $latestAgain = @($latest | Get-GitHubRelease) - It 'Should be the same release' { - $latest[0].ReleaseId | Should -Be $latestAgain[0].ReleaseId + $latestAgain = @($latest | Get-GitHubRelease) + It 'Should be the same release' { + $latest[0].ReleaseId | Should -Be $latestAgain[0].ReleaseId + } } - } - } - Context 'When getting a specific release' { - $specificIndex = 5 - $specific = @(Get-GitHubRelease -OwnerName $script:dotNetCoreOwnerName -RepositoryName $script:dotNetCoreRepositoryName -ReleaseId $releases[$specificIndex].id) + Context 'When getting a specific release' { + $specificIndex = 5 + $specific = @(Get-GitHubRelease -OwnerName $dotNetOwnerName -RepositoryName $repositoryName -ReleaseId $releases[$specificIndex].id) - It 'Should return one value' { - $specific.Count | Should -Be 1 - } + It 'Should return one value' { + $specific.Count | Should -Be 1 + } - It 'Should return the correct release' { - $specific.name | Should -Be $releases[$specificIndex].name - } + It 'Should return the correct release' { + $specific.name | Should -Be $releases[$specificIndex].name + } - It 'Should have expected type and additional properties' { - $specific[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' - $specific[0].html_url.StartsWith($specific[0].RepositoryUrl) | Should -BeTrue - $specific[0].id | Should -Be $specific[0].ReleaseId + It 'Should have expected type and additional properties' { + $specific[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $specific[0].html_url.StartsWith($specific[0].RepositoryUrl) | Should -BeTrue + $specific[0].id | Should -Be $specific[0].ReleaseId + } } - } - Context 'When getting a tagged release' { - $taggedIndex = 8 - $tagged = @(Get-GitHubRelease -OwnerName $script:dotNetCoreOwnerName -RepositoryName $script:dotNetCoreRepositoryName -Tag $releases[$taggedIndex].tag_name) + Context 'When getting a tagged release' { + $taggedIndex = 8 + $tagged = @(Get-GitHubRelease -OwnerName $dotNetOwnerName -RepositoryName $repositoryName -Tag $releases[$taggedIndex].tag_name) - It 'Should return one value' { - $tagged.Count | Should -Be 1 - } + It 'Should return one value' { + $tagged.Count | Should -Be 1 + } - It 'Should return the correct release' { - $tagged.name | Should -Be $releases[$taggedIndex].name - } + It 'Should return the correct release' { + $tagged.name | Should -Be $releases[$taggedIndex].name + } - It 'Should have expected type and additional properties' { - $tagged[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' - $tagged[0].html_url.StartsWith($tagged[0].RepositoryUrl) | Should -BeTrue - $tagged[0].id | Should -Be $tagged[0].ReleaseId + It 'Should have expected type and additional properties' { + $tagged[0].PSObject.TypeNames[0] | Should -Be 'GitHub.Release' + $tagged[0].html_url.StartsWith($tagged[0].RepositoryUrl) | Should -BeTrue + $tagged[0].id | Should -Be $tagged[0].ReleaseId + } } } } Describe 'Getting releases from default owner/repository' { - $originalOwnerName = Get-GitHubConfiguration -Name DefaultOwnerName - $originalRepositoryName = Get-GitHubConfiguration -Name DefaultRepositoryName + Context 'Common test state' { + BeforeAll { + $originalOwnerName = Get-GitHubConfiguration -Name DefaultOwnerName + $originalRepositoryName = Get-GitHubConfiguration -Name DefaultRepositoryName + + Set-GitHubConfiguration -DefaultOwnerName "dotnet" + Set-GitHubConfiguration -DefaultRepositoryName "core" + } - try { - Set-GitHubConfiguration -DefaultOwnerName "dotnet" - Set-GitHubConfiguration -DefaultRepositoryName "core" - $releases = @(Get-GitHubRelease) + AfterAll { + Set-GitHubConfiguration -DefaultOwnerName $originalOwnerName + Set-GitHubConfiguration -DefaultRepositoryName $originalRepositoryName + } Context 'When getting all releases' { + $releases = @(Get-GitHubRelease) + It 'Should return multiple releases' { $releases.Count | Should -BeGreaterThan 1 } } - } finally { - Set-GitHubConfiguration -DefaultOwnerName $originalOwnerName - Set-GitHubConfiguration -DefaultRepositoryName $originalRepositoryName - } - finally - { - Set-GitHubConfiguration -DefaultOwnerName $originalOwnerName - Set-GitHubConfiguration -DefaultRepositoryName $originalRepositoryName } } Describe 'Creating, changing and deleting releases with defaults' { - BeforeAll { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private - $release = New-GitHubRelease -Uri $repo.svn_url -TagName $script:defaultTagName - $queried = Get-GitHubRelease -Uri $repo.svn_url -Release $release.id - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $queried = $queried - } - - AfterAll { - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false - } + Context 'Common test state' { + BeforeAll { + $defaultTagName = '0.2.0' + $defaultReleaseName = 'Release Name' + $defaultReleaseBody = 'Releasey Body' + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private + $release = New-GitHubRelease -Uri $repo.svn_url -TagName $defaultTagName + $queried = Get-GitHubRelease -Uri $repo.svn_url -Release $release.id - Context 'When creating a simple new release' { - It 'Should be queryable' { - $queried.id | Should -Be $release.id - $queried.tag_name | Should -Be $script:defaultTagName + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $queried = $queried } - It 'Should have the expected default property values' { - $queried.name | Should -BeNullOrEmpty - $queried.body | Should -BeNullOrEmpty - $queried.draft | Should -BeFalse - $queried.prerelease | Should -BeFalse + AfterAll { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false } - It 'Should be modifiable' { - Set-GitHubRelease -Uri $repo.svn_url -Release $release.id -Name $script:defaultReleaseName -Body $script:defaultReleaseBody -Draft -PreRelease - $queried = Get-GitHubRelease -Uri $repo.svn_url -Release $release.id - $queried.name | Should -Be $script:defaultReleaseName - $queried.body | Should -Be $script:defaultReleaseBody - $queried.draft | Should -BeTrue - $queried.prerelease | Should -BeTrue - } + Context 'When creating a simple new release' { + It 'Should be queryable' { + $queried.id | Should -Be $release.id + $queried.tag_name | Should -Be $defaultTagName + } + + It 'Should have the expected default property values' { + $queried.name | Should -BeNullOrEmpty + $queried.body | Should -BeNullOrEmpty + $queried.draft | Should -BeFalse + $queried.prerelease | Should -BeFalse + } + + It 'Should be modifiable' { + Set-GitHubRelease -Uri $repo.svn_url -Release $release.id -Name $defaultReleaseName -Body $defaultReleaseBody -Draft -PreRelease + $queried = Get-GitHubRelease -Uri $repo.svn_url -Release $release.id + $queried.name | Should -Be $defaultReleaseName + $queried.body | Should -Be $defaultReleaseBody + $queried.draft | Should -BeTrue + $queried.prerelease | Should -BeTrue + } - It 'Should be removable' { - Remove-GitHubRelease -Uri $repo.svn_url -Release $release.id -Confirm:$false - { Get-GitHubRelease -Uri $repo.svn_url -Release $release.id } | Should -Throw + It 'Should be removable' { + Remove-GitHubRelease -Uri $repo.svn_url -Release $release.id -Confirm:$false + { Get-GitHubRelease -Uri $repo.svn_url -Release $release.id } | Should -Throw + } } } } Describe 'Creating, changing and deleting releases with non-defaults' { - BeforeAll { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private - $release = New-GitHubRelease -Uri $repo.svn_url -TagName $script:defaultTagName -Name $script:defaultReleaseName -Body $script:defaultReleaseBody -Draft -PreRelease - $queried = Get-GitHubRelease -Uri $repo.svn_url -Release $release.id + Context 'Common test state' { + BeforeAll { + $defaultTagName = '0.2.0' + $defaultReleaseName = 'Release Name' + $defaultReleaseBody = 'Releasey Body' + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private + $release = New-GitHubRelease -Uri $repo.svn_url -TagName $defaultTagName -Name $defaultReleaseName -Body $defaultReleaseBody -Draft -PreRelease + $queried = Get-GitHubRelease -Uri $repo.svn_url -Release $release.id - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $queried = $queried - } + # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments + $queried = $queried + } - AfterAll { - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false - } + AfterAll { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } - Context 'When creating a simple new release' { - It 'Should be creatable with non-default property values' { - $queried.id | Should -Be $release.id - $queried.tag_name | Should -Be $script:defaultTagName - $queried.name | Should -Be $script:defaultReleaseName - $queried.body | Should -Be $script:defaultReleaseBody - $queried.draft | Should -BeTrue - $queried.prerelease | Should -BeTrue + Context 'When creating a simple new release' { + It 'Should be creatable with non-default property values' { + $queried.id | Should -Be $release.id + $queried.tag_name | Should -Be $defaultTagName + $queried.name | Should -Be $defaultReleaseName + $queried.body | Should -Be $defaultReleaseBody + $queried.draft | Should -BeTrue + $queried.prerelease | Should -BeTrue + } } } } Describe 'Creating, changing and deleting release assets' { - BeforeAll { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private - $release = New-GitHubRelease -Uri $repo.svn_url -TagName $script:defaultTagName + Context 'Validating release assets' { + BeforeAll { + # To get access to New-TemporaryDirectory + $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent + . (Join-Path -Path $moduleRootPath -ChildPath 'Helpers.ps1') - $tempFile = New-TemporaryFile - $zipFile = "$($tempFile.FullName).zip" - Move-Item -Path $tempFile -Destination $zipFile + $defaultTagName = '0.2.0' - $tempFile = New-TemporaryFile - $txtFile = "$($tempFile.FullName).txt" - Move-Item -Path $tempFile -Destination $txtFile - Out-File -FilePath $txtFile -InputObject "txt file content" -Encoding utf8 + $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private + $release = New-GitHubRelease -Uri $repo.svn_url -TagName $defaultTagName - Compress-Archive -Path $txtFile -DestinationPath $zipFile -Force + $tempFile = New-TemporaryFile + $zipFile = "$($tempFile.FullName).zip" + Move-Item -Path $tempFile -Destination $zipFile - $label = 'mylabel' + $tempFile = New-TemporaryFile + $txtFile = "$($tempFile.FullName).txt" + Move-Item -Path $tempFile -Destination $txtFile + Out-File -FilePath $txtFile -InputObject "txt file content" -Encoding utf8 - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $release = $release - $label = $label - $asset = $asset - } + # Disable Progress Bar in function scope during Compress-Archive + $ProgressPreference = 'SilentlyContinue' + Compress-Archive -Path $txtFile -DestinationPath $zipFile -Force - AfterAll { - @($zipFile, $txtFile) | Remove-Item | Out-Null - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false - } + $label = 'mylabel' + } - It "Can add a release asset" { - $asset = New-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id -Path $zipFile -Label $label - $zipFileName = (Get-Item -Path $zipFile).Name - $assetId = $asset.id + AfterAll { + @($zipFile, $txtFile) | Remove-Item | Out-Null + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } - $asset.name | Should -BeExactly $zipFileName - $asset.label | Should -BeExactly $label - } + It "Can add a release asset" { + $asset = New-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id -Path $zipFile -Label $label + $zipFileName = (Get-Item -Path $zipFile).Name + $assetId = $asset.id - It "Can list release assets" { - $result = @(Get-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id) - $zipFileName = (Get-Item -Path $zipFile).Name + $asset.name | Should -BeExactly $zipFileName + $asset.label | Should -BeExactly $label + } - $result.count | Should -Be 1 - $result[0].name | Should -BeExactly $zipFileName - $result[0].label | Should -BeExactly $label - } + It "Can list release assets" { + $result = @(Get-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id) + $zipFileName = (Get-Item -Path $zipFile).Name - It "Can download release assets" { - try - { - $tempFile = New-TemporaryFile - $downloadedZipFile = "$($tempFile.FullName).zip" - Move-Item -Path $tempFile -Destination $downloadedZipFile + $result.count | Should -Be 1 + $result[0].name | Should -BeExactly $zipFileName + $result[0].label | Should -BeExactly $label + } + It "Can download release assets" { $tempPath = New-TemporaryDirectory - $assetId = @(Get-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id)[0].id - $result = Get-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId -Path $downloadedZipFile -Force - Expand-Archive -Path $downloadedZipFile -DestinationPath $tempPath + try + { + $tempFile = New-TemporaryFile + $downloadedZipFile = "$($tempFile.FullName).zip" + Move-Item -Path $tempFile -Destination $downloadedZipFile - $result.FullName | Should -BeExactly $downloadedZipFile + $assetId = @(Get-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id)[0].id + $result = Get-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId -Path $downloadedZipFile -Force + Expand-Archive -Path $downloadedZipFile -DestinationPath $tempPath - $txtFileName = (Get-Item -Path $txtFile).Name - $downloadedTxtFile = (Get-ChildItem -Path $tempPath -Filter $txtFileName).FullName - (Get-Content -Path $txtFile -Raw) | Should -BeExactly (Get-Content -Path $downloadedTxtFile -Raw) - } - finally - { - Remove-Item -Path $downloadedZipFile - Remove-Item -Path $tempPath -Recurse -Force + $result.FullName | Should -BeExactly $downloadedZipFile + + $txtFileName = (Get-Item -Path $txtFile).Name + $downloadedTxtFile = (Get-ChildItem -Path $tempPath -Filter $txtFileName).FullName + (Get-Content -Path $txtFile -Raw) | Should -BeExactly (Get-Content -Path $downloadedTxtFile -Raw) + } + finally + { + Remove-Item -Path $downloadedZipFile + Remove-Item -Path $tempPath -Recurse -Force + } } - } - It "Can update a release asset" { - $newFileName = 'newFileName.zip' - $newLabel = 'my new label' + It "Can update a release asset" { + $newFileName = 'newFileName.zip' + $newLabel = 'my new label' - $assetId = @(Get-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id)[0].id - $null = Set-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId -Name $newFileName -Label $newLabel - $result = Get-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId + $assetId = @(Get-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id)[0].id + $null = Set-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId -Name $newFileName -Label $newLabel + $result = Get-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId - $result.name | Should -BeExactly $newFileName - $result.label | Should -BeExactly $newLabel - } + $result.name | Should -BeExactly $newFileName + $result.label | Should -BeExactly $newLabel + } - It "Can remove a release asset" { - $assetId = @(Get-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id)[0].id - Remove-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId -Confirm:$false - { Get-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId } | Should -Throw + It "Can remove a release asset" { + $assetId = @(Get-GitHubReleaseAsset -Uri $repo.svn_url -Release $release.id)[0].id + Remove-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId -Confirm:$false + { Get-GitHubReleaseAsset -Uri $repo.svn_url -Asset $assetId } | Should -Throw + } } } } @@ -312,4 +331,4 @@ finally Restore-GitHubConfiguration -Path $script:originalConfigFile $script:originalConfigFile = $null } -} +} \ No newline at end of file