From 6b13df1872de4b2c1e0bc51ffbfa70775a8bd4fc Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Thu, 18 Jun 2020 02:06:37 -0700 Subject: [PATCH] Update the tests and functions to accomodate latest master changes --- GitHubAssignees.ps1 | 4 + GitHubBranches.ps1 | 1 + GitHubContents.ps1 | 1 + GitHubCore.ps1 | 2 +- GitHubEvents.ps1 | 1 + GitHubIssueComments.ps1 | 4 + GitHubIssues.ps1 | 6 + GitHubLabels.ps1 | 8 + GitHubMilestones.ps1 | 4 + GitHubMiscellaneous.ps1 | 2 + GitHubProjects.ps1 | 4 + GitHubPullRequests.ps1 | 2 + GitHubReleases.ps1 | 254 +++++++++++++++++--- GitHubRepositories.ps1 | 12 + GitHubRepositoryForks.ps1 | 2 + GitHubRepositoryTraffic.ps1 | 4 + GitHubTeams.ps1 | 2 + Tests/GitHubReleases.tests.ps1 | 427 +++++++++++++++++---------------- 18 files changed, 502 insertions(+), 238 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 0964573a..79ee9f95 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -45,6 +45,7 @@ filter Get-GitHubAssignee GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -157,6 +158,7 @@ filter Test-GitHubAssignee GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -300,6 +302,7 @@ function Add-GitHubAssignee GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -477,6 +480,7 @@ function Remove-GitHubAssignee GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubBranches.ps1 b/GitHubBranches.ps1 index f595ace7..518ad9cf 100644 --- a/GitHubBranches.ps1 +++ b/GitHubBranches.ps1 @@ -57,6 +57,7 @@ filter Get-GitHubRepositoryBranch GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubContents.ps1 b/GitHubContents.ps1 index 7ce6472a..f6a49e3b 100644 --- a/GitHubContents.ps1 +++ b/GitHubContents.ps1 @@ -72,6 +72,7 @@ GitHub.ProjectCard GitHub.ProjectColumn 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 c904bc6a..6446eb1f 100644 --- a/GitHubEvents.ps1 +++ b/GitHubEvents.ps1 @@ -59,6 +59,7 @@ filter Get-GitHubEvent GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubIssueComments.ps1 b/GitHubIssueComments.ps1 index 1eacf806..f34d578e 100644 --- a/GitHubIssueComments.ps1 +++ b/GitHubIssueComments.ps1 @@ -80,6 +80,7 @@ filter Get-GitHubIssueComment GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -344,6 +345,7 @@ filter New-GitHubIssueComment GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -487,6 +489,7 @@ filter Set-GitHubIssueComment GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -617,6 +620,7 @@ filter Remove-GitHubIssueComment GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 1010b19a..a48c63c1 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -129,6 +129,7 @@ filter Get-GitHubIssue GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.User @@ -432,6 +433,7 @@ filter Get-GitHubIssueTimeline GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -570,6 +572,7 @@ filter New-GitHubIssue GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -738,6 +741,7 @@ filter Set-GitHubIssue GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -888,6 +892,7 @@ filter Lock-GitHubIssue GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE @@ -1018,6 +1023,7 @@ filter Unlock-GitHubIssue GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 80f55480..d6edc2bc 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -64,6 +64,7 @@ filter Get-GitHubLabel GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -251,6 +252,7 @@ filter New-GitHubLabel GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -392,6 +394,7 @@ filter Remove-GitHubLabel GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE @@ -549,6 +552,7 @@ filter Set-GitHubLabel GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -695,6 +699,7 @@ filter Initialize-GitHubLabel GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE @@ -834,6 +839,7 @@ function Add-GitHubIssueLabel GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -994,6 +1000,7 @@ function Set-GitHubIssueLabel GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1185,6 +1192,7 @@ filter Remove-GitHubIssueLabel GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubMilestones.ps1 b/GitHubMilestones.ps1 index ddbbd165..9d253a65 100644 --- a/GitHubMilestones.ps1 +++ b/GitHubMilestones.ps1 @@ -68,6 +68,7 @@ filter Get-GitHubMilestone GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -270,6 +271,7 @@ filter New-GitHubMilestone GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -451,6 +453,7 @@ filter Set-GitHubMilestone GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -631,6 +634,7 @@ filter Remove-GitHubMilestone GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubMiscellaneous.ps1 b/GitHubMiscellaneous.ps1 index a2498de5..8ba90967 100644 --- a/GitHubMiscellaneous.ps1 +++ b/GitHubMiscellaneous.ps1 @@ -250,6 +250,7 @@ filter Get-GitHubLicense GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository @@ -488,6 +489,7 @@ filter Get-GitHubCodeOfConduct GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository diff --git a/GitHubProjects.ps1 b/GitHubProjects.ps1 index 3476f263..b9639576 100644 --- a/GitHubProjects.ps1 +++ b/GitHubProjects.ps1 @@ -63,6 +63,7 @@ filter Get-GitHubProject GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -275,6 +276,7 @@ filter New-GitHubProject GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -455,6 +457,7 @@ filter Set-GitHubProject GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -583,6 +586,7 @@ filter Remove-GitHubProject GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE diff --git a/GitHubPullRequests.ps1 b/GitHubPullRequests.ps1 index 09860e02..e7359124 100644 --- a/GitHubPullRequests.ps1 +++ b/GitHubPullRequests.ps1 @@ -77,6 +77,7 @@ filter Get-GitHubPullRequest GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -272,6 +273,7 @@ filter New-GitHubPullRequest GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubReleases.ps1 b/GitHubReleases.ps1 index 55e283b8..2e15d2c7 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 } @@ -66,6 +67,7 @@ filter Get-GitHubRelease GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -278,6 +280,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 @@ -290,6 +311,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')] @@ -351,22 +373,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 @@ -426,6 +443,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' @@ -435,6 +471,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')] @@ -500,22 +537,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 @@ -555,6 +587,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 @@ -583,7 +631,7 @@ filter Remove-GitHubRelease Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='Uri')] - [Alias('ReositoryUrl')] + [Alias('RepositoryUrl')] [string] $Uri, [Parameter( @@ -609,9 +657,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 @@ -670,6 +718,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 @@ -684,6 +751,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( @@ -795,9 +863,9 @@ filter Get-GitHubReleaseAsset } $params = @{ - 'UriFragment' = $uriFragment + 'UriFragment' = $uriFragment 'Method' = 'Get' - 'Description' = $description + 'Description' = $description 'AcceptHeader' = $acceptHeader 'Save' = $shouldSave 'AccessToken' = $AccessToken @@ -815,7 +883,7 @@ filter Get-GitHubReleaseAsset } else { - return $result + return ($result | Add-GitHubReleaseAssetAdditionalProperties) } } @@ -870,6 +938,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 @@ -883,6 +970,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( @@ -916,9 +1004,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, @@ -948,7 +1038,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 } @@ -968,9 +1066,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 @@ -979,7 +1077,7 @@ filter New-GitHubReleaseAsset 'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus) } - return Invoke-GHRestMethod @params + return (Invoke-GHRestMethod @params | Add-GitHubReleaseAssetAdditionalProperties) } filter Set-GitHubReleaseAsset @@ -1025,6 +1123,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 @@ -1036,6 +1153,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( @@ -1085,17 +1203,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 @@ -1135,6 +1253,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 @@ -1186,9 +1320,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 @@ -1257,3 +1391,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 847e82b5..a05d2f43 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 @@ -449,6 +450,7 @@ filter Remove-GitHubRepository GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .EXAMPLE @@ -615,6 +617,7 @@ filter Get-GitHubRepository GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -939,6 +942,7 @@ filter Rename-GitHubRepository GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1120,6 +1124,7 @@ filter Set-GitHubRepository GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1304,6 +1309,7 @@ filter Get-GitHubRepositoryTopic GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1419,6 +1425,7 @@ function Set-GitHubRepositoryTopic GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1606,6 +1613,7 @@ filter Get-GitHubRepositoryContributor GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1758,6 +1766,7 @@ filter Get-GitHubRepositoryCollaborator GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1876,6 +1885,7 @@ filter Get-GitHubRepositoryLanguage GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -1984,6 +1994,7 @@ filter Get-GitHubRepositoryTag GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -2098,6 +2109,7 @@ filter Move-GitHubRepositoryOwnership GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubRepositoryForks.ps1 b/GitHubRepositoryForks.ps1 index 98e311d2..3dffa1c3 100644 --- a/GitHubRepositoryForks.ps1 +++ b/GitHubRepositoryForks.ps1 @@ -51,6 +51,7 @@ filter Get-GitHubRepositoryFork GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -168,6 +169,7 @@ filter New-GitHubRepositoryFork GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubRepositoryTraffic.ps1 b/GitHubRepositoryTraffic.ps1 index d3c26ddd..5c67e0ff 100644 --- a/GitHubRepositoryTraffic.ps1 +++ b/GitHubRepositoryTraffic.ps1 @@ -57,6 +57,7 @@ filter Get-GitHubReferrerTraffic GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -170,6 +171,7 @@ filter Get-GitHubPathTraffic GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -290,6 +292,7 @@ filter Get-GitHubViewTraffic GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS @@ -414,6 +417,7 @@ filter Get-GitHubCloneTraffic GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository .OUTPUTS diff --git a/GitHubTeams.ps1 b/GitHubTeams.ps1 index 54b1f809..fe3925fc 100644 --- a/GitHubTeams.ps1 +++ b/GitHubTeams.ps1 @@ -61,6 +61,7 @@ filter Get-GitHubTeam GitHub.ProjectCard GitHub.ProjectColumn GitHub.Release + GitHub.ReleaseAsset GitHub.Repository GitHub.Team @@ -200,6 +201,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