From 07a284a25f022aa2206d5312f513bd0a6824e113 Mon Sep 17 00:00:00 2001 From: Donovan Brown Date: Fri, 2 Oct 2020 08:34:01 -0500 Subject: [PATCH] Added Update-VSTeamNuGetPackageVersion (#358) Added Update-VSTeamNuGetPackageVersion Updated changelog and version to 7.1.0 --- .docs/Update-VSTeamNuGetPackageVersion.md | 73 +++++++++++++++++++ .../Update-VSTeamNuGetPackageVersion.md | 1 + CHANGELOG.md | 3 +- .../Update-VSTeamNuGetPackageVersion.ps1 | 40 ++++++++++ Source/VSTeam.psd1 | 2 +- ...vsteam_lib.PackageVersion.TableView.ps1xml | 6 ++ .../tests/Update-VSTeamExtension.Tests.ps1 | 5 +- ...Update-VSTeamNuGetPackageVersion.Tests.ps1 | 34 +++++++++ Tests/integration/tests/040_Format.Tests.ps1 | 5 +- 9 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 .docs/Update-VSTeamNuGetPackageVersion.md create mode 100644 .docs/synopsis/Update-VSTeamNuGetPackageVersion.md create mode 100644 Source/Public/Update-VSTeamNuGetPackageVersion.ps1 create mode 100644 Tests/function/tests/Update-VSTeamNuGetPackageVersion.Tests.ps1 diff --git a/.docs/Update-VSTeamNuGetPackageVersion.md b/.docs/Update-VSTeamNuGetPackageVersion.md new file mode 100644 index 000000000..d0019f6f9 --- /dev/null +++ b/.docs/Update-VSTeamNuGetPackageVersion.md @@ -0,0 +1,73 @@ + + +# Update-VSTeamNuGetPackageVersion + +## SYNOPSIS + + + +## SYNTAX + +## DESCRIPTION + + + +## EXAMPLES + +### Example 1 + +```powershell +Get-VSTeamPackageVersion -feedName ber -packageId 0d64db64-c7b7-412e-83f4-68c5f2bfc3d8 | Update-VSTeamNuGetPackageVersion -FeedId ber -PackageName Trackyon.Ber -isListed $false +``` + +This command un-lists every version of Trackyon.Ber in the ber feed. + +## PARAMETERS + +### FeedId + +Name or Id of the feed. + +```yaml +Type: String +Required: True +Aliases: feedName +``` + +### PackageName + +Name of the package to update. This cannot be the id. + +```yaml +Type: String +Required: True +``` + +### PackageVersion + +Version of the package to update. + +```yaml +Type: String[] +Required: True +Aliases: Version +Accept pipeline input: true (ByValue, ByPropertyName) +``` + + + +## INPUTS + +## OUTPUTS + +## NOTES + + + +## RELATED LINKS + + + +[Get-VSTeamPackage](Get-VSTeamPackage.md) + +[Get-VSTeamPackageVersion](Get-VSTeamPackageVersion.md) diff --git a/.docs/synopsis/Update-VSTeamNuGetPackageVersion.md b/.docs/synopsis/Update-VSTeamNuGetPackageVersion.md new file mode 100644 index 000000000..942f6d6e1 --- /dev/null +++ b/.docs/synopsis/Update-VSTeamNuGetPackageVersion.md @@ -0,0 +1 @@ +Set mutable state on a package version. \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c999349ad..33bec12a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ # Changelog -## Next +## 7.1.0 Added: - Get-VSTeamPackage to return packages of a feed. - Show-VSTeamPackage to open package in default browser. - Get-VSTeamPackageVersion to return all the versions of a package. +- Update-VSTeamNuGetPackageVersion to list and un-list versions. ## 7.0.1 diff --git a/Source/Public/Update-VSTeamNuGetPackageVersion.ps1 b/Source/Public/Update-VSTeamNuGetPackageVersion.ps1 new file mode 100644 index 000000000..65567d1dc --- /dev/null +++ b/Source/Public/Update-VSTeamNuGetPackageVersion.ps1 @@ -0,0 +1,40 @@ +function Update-VSTeamNuGetPackageVersion { + [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "Medium", + HelpUri = 'https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Update-VSTeamNuGetPackageVersion')] + param ( + [parameter(Mandatory)] + [Alias("feedName")] + [string] $FeedId, + + [parameter(Mandatory)] + [string] $PackageName, + + [parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] + [Alias("Version")] + [string[]] $PackageVersion, + + [parameter(Mandatory = $true)] + [bool] $isListed, + + [switch] $Force + ) + process { + foreach ($item in $PackageVersion) { + if ($Force -or $pscmdlet.ShouldProcess($item, "update version")) { + + $obj = @{ + listed = $isListed + } + + $body = $obj | ConvertTo-Json -Compress + + _callAPI -Method PATCH -SubDomain pkgs ` + -Area "packaging/feeds/$FeedId/nuget" ` + -Resource "packages/$PackageName/versions" ` + -Id $item ` + -Body $body ` + -Version $(_getApiVersion Packaging) | Out-Null + } + } + } +} \ No newline at end of file diff --git a/Source/VSTeam.psd1 b/Source/VSTeam.psd1 index 8719b3cfc..a93b5f437 100644 --- a/Source/VSTeam.psd1 +++ b/Source/VSTeam.psd1 @@ -12,7 +12,7 @@ RootModule = 'VSTeam.psm1' # Version number of this module. - ModuleVersion = '7.0.1' + ModuleVersion = '7.1.0' # Supported PSEditions CompatiblePSEditions = @('Core', 'Desktop') diff --git a/Source/formats/vsteam_lib.PackageVersion.TableView.ps1xml b/Source/formats/vsteam_lib.PackageVersion.TableView.ps1xml index 7f83ff927..ec9e84a7d 100644 --- a/Source/formats/vsteam_lib.PackageVersion.TableView.ps1xml +++ b/Source/formats/vsteam_lib.PackageVersion.TableView.ps1xml @@ -12,6 +12,9 @@ + + + @@ -26,6 +29,9 @@ Version + + IsListed + PublishDate diff --git a/Tests/function/tests/Update-VSTeamExtension.Tests.ps1 b/Tests/function/tests/Update-VSTeamExtension.Tests.ps1 index b26b444da..c0d3cb2ff 100644 --- a/Tests/function/tests/Update-VSTeamExtension.Tests.ps1 +++ b/Tests/function/tests/Update-VSTeamExtension.Tests.ps1 @@ -3,8 +3,6 @@ Set-StrictMode -Version Latest Describe 'VSTeamExtension' { BeforeAll { . "$PSScriptRoot\_testInitialize.ps1" $PSCommandPath - - Mock _getInstance { return 'https://dev.azure.com/test' } } Context 'Update-VSTeamExtension' { @@ -21,10 +19,9 @@ Describe 'VSTeamExtension' { Update-VSTeamExtension -PublisherId 'test' -ExtensionId 'test' -ExtensionState disabled -Force Should -Invoke _callAPI -Exactly 1 -Scope It -ParameterFilter { - $Method -eq 'Post' -and + $Method -eq 'Patch' -and $subDomain -eq 'extmgmt' -and $version -eq [vsteam_lib.Versions]::ExtensionsManagement - $Url -like "*https://extmgmt.dev.azure.com/test/_apis/_apis/extensionmanagement/installedextensionsbyname/test/test*" } } } diff --git a/Tests/function/tests/Update-VSTeamNuGetPackageVersion.Tests.ps1 b/Tests/function/tests/Update-VSTeamNuGetPackageVersion.Tests.ps1 new file mode 100644 index 000000000..2c53c15bd --- /dev/null +++ b/Tests/function/tests/Update-VSTeamNuGetPackageVersion.Tests.ps1 @@ -0,0 +1,34 @@ +Set-StrictMode -Version Latest + +Describe 'VSTeamNuGetPackageVersion' { + BeforeAll { + . "$PSScriptRoot\_testInitialize.ps1" $PSCommandPath + } + + Context 'Update-VSTeamNuGetPackageVersion' { + BeforeAll { + $env:Team_TOKEN = '1234' + Mock _callAPI { Open-SampleFile 'Get-VSTeamPackageVersion.json' -Index 0 } + } + + AfterAll { + $env:TEAM_TOKEN = $null + } + + # id : 36c9353b-e250-4c57-b040-513c186c3905 + # area : nuget + # resourceName : Versions + # routeTemplate : {project}/_apis/packaging/feeds/{feedId}/{area}/packages/{packageName}/{resource}/{packageVersion} + It 'Should unlist version' { + Update-VSTeamNuGetPackageVersion -FeedId 'feedName' -packageName 'packageName' -packageVersion '1137.0.0' -isListed $false -Force + + Should -Invoke _callAPI -Exactly 1 -Scope It -ParameterFilter { + $Method -eq 'Patch' -and + $Area -eq 'packaging/feeds/feedName/nuget' -and + $Resource -eq 'packages/packageName/Versions' -and + $subDomain -eq 'pkgs' -and + $version -eq [vsteam_lib.Versions]::Packaging + } + } + } +} \ No newline at end of file diff --git a/Tests/integration/tests/040_Format.Tests.ps1 b/Tests/integration/tests/040_Format.Tests.ps1 index 4d7315b59..caef95994 100644 --- a/Tests/integration/tests/040_Format.Tests.ps1 +++ b/Tests/integration/tests/040_Format.Tests.ps1 @@ -160,7 +160,8 @@ Describe 'Table Formats for Provider classes' -Tag 'integration' { $cols = Get-Columns -TypeName vsteam_lib.PackageVersion $cols[0] | Should -Be 'Version' - $cols[1] | Should -Be 'Publish Date' + $cols[1] | Should -Be 'Listed' + $cols[2] | Should -Be 'Publish Date' } } -} \ No newline at end of file +}