diff --git a/.docs/Show-VSTeamPackage.md b/.docs/Show-VSTeamPackage.md new file mode 100644 index 000000000..25fdc2459 --- /dev/null +++ b/.docs/Show-VSTeamPackage.md @@ -0,0 +1,63 @@ + + +# Show-VSTeamPackage + +## SYNOPSIS + + + +## SYNTAX + +## DESCRIPTION + + + +## EXAMPLES + +### Example 1: From pipeline + +```powershell +Get-VSTeamPackage -feedName vsteam -Top 1 -Skip 2 | Show-VSTeamPackage +``` + +This command will open a web browser with this package showing. + +### Example 2: By parameter + +```powershell +$p = Get-VSTeamPackage -feedName vsteam -Top 1 -Skip 2 +Show-VSTeamPackage $p +``` + +This command will open a web browser with this package showing. + +## PARAMETERS + +### Package + +Package to show + +```yaml +Type: vsteam_lib.Package +Required: True +Position: 0 +Accept pipeline input: true (ByPropertyName) +``` + +## INPUTS + +### vsteam_lib.Package + +## OUTPUTS + +### vsteam_lib.Package + +## NOTES + + + +## RELATED LINKS + + + +[Add-VSTeamPackage](Add-VSTeamPackage.md) diff --git a/.docs/synopsis/Show-VSTeamPackage.md b/.docs/synopsis/Show-VSTeamPackage.md new file mode 100644 index 000000000..29de25ed1 --- /dev/null +++ b/.docs/synopsis/Show-VSTeamPackage.md @@ -0,0 +1 @@ +Opens the package in the default browser. \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d66b49f9..8a26b69f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Next Added Get-VSTeamPackage to return packages of a feed. +Added Show-VSTeamPackage to open package in default browser. ## 7.0.1 diff --git a/Source/Classes/Provider/Package.cs b/Source/Classes/Provider/Package.cs index 125c28b75..e3c1f880b 100644 --- a/Source/Classes/Provider/Package.cs +++ b/Source/Classes/Provider/Package.cs @@ -15,12 +15,16 @@ public class Package : Directory public object Versions { get; set; } public Link Links { get; } + public string FeedId { get; } + /// /// Used for testing /// - public Package(PSObject obj, IPowerShell powerShell) : + public Package(PSObject obj, string feedId, IPowerShell powerShell) : base(obj, obj.GetValue("name"), "Version", powerShell, null) { + this.FeedId = feedId; + if (obj.HasValue("_links")) { this.Links = new Link(obj); @@ -31,8 +35,8 @@ public Package(PSObject obj, IPowerShell powerShell) : /// Used by PowerShell /// [ExcludeFromCodeCoverage] - public Package(PSObject obj) : - this(obj, new PowerShellWrapper(RunspaceMode.CurrentRunspace)) + public Package(PSObject obj, string feedId) : + this(obj, feedId, new PowerShellWrapper(RunspaceMode.CurrentRunspace)) { } } diff --git a/Source/Public/Get-VSTeamPackage.ps1 b/Source/Public/Get-VSTeamPackage.ps1 index 39dbba399..0807f9a85 100644 --- a/Source/Public/Get-VSTeamPackage.ps1 +++ b/Source/Public/Get-VSTeamPackage.ps1 @@ -59,13 +59,13 @@ function Get-VSTeamPackage { -Version $(_getApiVersion packaging) if ($null -ne $packageId) { - return [vsteam_lib.Package]::new($resp) + return [vsteam_lib.Package]::new($resp, $feedId) } $objs = @() foreach ($item in $resp.value) { - $objs += [vsteam_lib.Package]::new($item, $ProjectName) + $objs += [vsteam_lib.Package]::new($item, $feedId) } Write-Output $objs diff --git a/Source/Public/Show-VSTeamPackage.ps1 b/Source/Public/Show-VSTeamPackage.ps1 new file mode 100644 index 000000000..d9edf7468 --- /dev/null +++ b/Source/Public/Show-VSTeamPackage.ps1 @@ -0,0 +1,13 @@ +function Show-VSTeamPackage { + [CmdletBinding(HelpUri='https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Show-VSTeamPackage')] + param( + [Parameter(Position = 0, Mandatory, ValueFromPipeline)] + [vsteam_lib.Package] $package + ) + + process { + _hasAccount + + Show-Browser "$(_getInstance)/_packaging?_a=package&feedName=$($package.FeedId)&package=$($package.Name)&protocolType=$($package.ProtocolType)&version=$($p.Versions[0].version)" + } +} \ No newline at end of file diff --git a/Tests/function/tests/Get-VSTeamPackage.Tests.ps1 b/Tests/function/tests/Get-VSTeamPackage.Tests.ps1 index 295dc0aca..f214ad3af 100644 --- a/Tests/function/tests/Get-VSTeamPackage.Tests.ps1 +++ b/Tests/function/tests/Get-VSTeamPackage.Tests.ps1 @@ -18,6 +18,7 @@ Describe 'VSTeamPackage' { ## Assert $actual.count | Should -Be 4 + $actual[0].FeedId | Should -Be '00000000-0000-0000-0000-000000000001' Should -Invoke _callApi -Exactly -Times 1 -Scope It -ParameterFilter { $Subdomain -eq 'feeds' -and diff --git a/Tests/function/tests/Show-VSTeamPackage.Tests.ps1 b/Tests/function/tests/Show-VSTeamPackage.Tests.ps1 new file mode 100644 index 000000000..6e68ae373 --- /dev/null +++ b/Tests/function/tests/Show-VSTeamPackage.Tests.ps1 @@ -0,0 +1,25 @@ +Set-StrictMode -Version Latest + +Describe 'VSTeamPackage' { + BeforeAll { + . "$PSScriptRoot\_testInitialize.ps1" $PSCommandPath + + ## Arrange + Mock Show-Browser + Mock _getInstance { return 'https://dev.azure.com/test' } + } + + Context 'Show-VSTeamPackage' { + It 'by name should call show-browser' { + ## Arrange + $p = [vsteam_lib.Package]::new($(Open-SampleFile 'Get-VSTeamPackage.json' -Index 0), + '00000000-0000-0000-0000-000000000001') + + ## Act + Show-VSTeamPackage $p + + ## Assert + Should -Invoke Show-Browser + } + } +} \ No newline at end of file diff --git a/Tests/library/Provider/PackageTests.cs b/Tests/library/Provider/PackageTests.cs index 15b9770e8..b4c58461d 100644 --- a/Tests/library/Provider/PackageTests.cs +++ b/Tests/library/Provider/PackageTests.cs @@ -16,10 +16,11 @@ public void Package_Constructor() var obj = BaseTests.LoadJson("Get-VSTeamPackage.json"); // Act - var actual = new Package(obj[2], ps); + var actual = new Package(obj[2], "MyFeed", ps); // Assert Assert.AreEqual("VSTeam", actual.Name, "Name"); + Assert.AreEqual("MyFeed", actual.FeedId, "FeedId"); Assert.AreEqual("NuGet", actual.ProtocolType, "ProtocolType"); Assert.AreEqual("vsteam", actual.NormalizedName, "NormalizedName"); Assert.AreEqual(Guid.Parse("6c163345-4ec5-0000-84a9-2693e6f066d0"), actual.Id, "Id");