From 8ade4e19b78f1bfed83cae02ad0fddcd41a46b52 Mon Sep 17 00:00:00 2001 From: Christopher Boden Date: Tue, 11 May 2021 12:03:01 -0500 Subject: [PATCH 1/4] Added -PullRequestID to Get-ADORepository --- Get-ADORepository.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Get-ADORepository.ps1 b/Get-ADORepository.ps1 index e6703b9a..d32bb3f6 100644 --- a/Get-ADORepository.ps1 +++ b/Get-ADORepository.ps1 @@ -41,6 +41,7 @@ [Parameter(Mandatory,ParameterSetName='git/repositories/{repositoryId}',ValueFromPipelineByPropertyName)] [Parameter(Mandatory,ParameterSetName='git/repositories/{repositoryId}/items',ValueFromPipelineByPropertyName)] [Parameter(Mandatory,ParameterSetName='git/repositories/{repositoryId}/pullrequests',ValueFromPipelineByPropertyName)] + [Parameter(Mandatory,ParameterSetName='git/repositories/{repositoryId}/pullrequests/{pullRequestId}',ValueFromPipelineByPropertyName)] [string] $RepositoryID, @@ -165,6 +166,12 @@ [string] $PullRequestStatus, + # Get pull request with a specific id + [Parameter(ParameterSetName='git/repositories/{repositoryId}/pullrequests/{pullRequestId}',ValueFromPipelineByPropertyName)] + [Alias('PRID')] + [string] + $PullRequestID, + # If set, will include the parent repository [Parameter(ParameterSetName='git/repositories/{repositoryId}',ValueFromPipelineByPropertyName)] [switch] @@ -350,7 +357,7 @@ elseif ($psParameterSet -eq 'git/repositories/{repositoryId}/items') { ".File" } - elseif ($psParameterSet -eq 'git/repositories/{repositoryId}/pullrequests') { + elseif ($psParameterSet -in ('git/repositories/{repositoryId}/pullrequests', 'git/repositories/{repositoryId}/pullrequests/{pullRequestId}')) { ".PullRequest" } else { From 7c3a95e6bbe690cdb43d6b523d5c3de7bc1d7221 Mon Sep 17 00:00:00 2001 From: Christopher Boden Date: Wed, 12 May 2021 15:34:06 -0500 Subject: [PATCH 2/4] Added skip for tests that won't work if the pull request is from a fork --- PSDevOps.tests.ps1 | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/PSDevOps.tests.ps1 b/PSDevOps.tests.ps1 index 6651525b..a5688c01 100644 --- a/PSDevOps.tests.ps1 +++ b/PSDevOps.tests.ps1 @@ -5,6 +5,12 @@ param( $TestProject = 'PSDevOps' ) +$IsFork = $env:SYSTEM_PULLREQUEST_ISFORK -eq 'true' + +if ($IsFork) { + Write-Verbose "Build is from a fork - some tests will be skipped" +} + Write-Verbose "Testing with $testOrg/$TestProject" $testPat = @@ -210,7 +216,7 @@ describe 'Creating Pipelines' { } describe 'Calling REST APIs' { - it 'Can invoke an Azure DevOps REST api' { + it 'Can invoke an Azure DevOps REST api' -Skip:$IsFork { $org = 'StartAutomating' $project = 'PSDevOps' Invoke-ADORestAPI "https://dev.azure.com/$org/$project/_apis/build/builds/?api-version=5.1" -PSTypeName AzureDevOps.Build @@ -238,7 +244,7 @@ describe 'Calling REST APIs' { Select-Object -ExpandProperty Name | Should -Be PSDevOps } - it 'Can create projects' { + it 'Can create projects' -Skip:$IsFork { $whatIfResult = New-ADOProject -Name TestProject -Description "A Test Project" -Public -Abbreviation 'TP' -Organization StartAutomating -Process Agile -WhatIf -PersonalAccessToken $testPat $bodyObject = $whatIfResult.body | ConvertFrom-Json @@ -302,7 +308,7 @@ describe 'Calling REST APIs' { Should -BeLike '*/git/repositories*' } - it 'Can Remove Repositories' { + it 'Can Remove Repositories' -Skip:$IsFork { $whatIf = Remove-ADORepository -Organization StartAutomating -Project PSDevOps -RepositoryID PSDevOps -WhatIf -PersonalAccessToken $testPat $whatIf.Method | Should -Be DELETE @@ -325,7 +331,7 @@ describe 'Calling REST APIs' { $buildDefinitions.Count | should -BeGreaterThan 1 $buildDefinitions[0].Name |should -beLike *PSDevOps* } - it 'Can get build -DefinitionYAML, given a build definition' { + it 'Can get build -DefinitionYAML, given a build definition' -Skip:$IsFork { $buildDefinitionYaml = $(Get-ADOBuild -Organization StartAutomating -Project PSDevOps -Definition | Select-Object -First 1 | Get-ADOBuild -DefinitionYAML -PersonalAccessToken $testPat) @@ -385,11 +391,11 @@ describe 'Calling REST APIs' { context 'Agent Pools' { # These tests will return nothing when run with a SystemAccessToken, so we will only fail if they error - it 'Can Get-ADOAgentPool for a given -Organization and -Project' { + it 'Can Get-ADOAgentPool for a given -Organization and -Project' -Skip:$IsFork { Get-ADOAgentPool -Organization StartAutomating -Project PSDevOps -PersonalAccessToken $testPat -ErrorAction Stop } - it 'Can Get-ADOAgentPool for a given -Organization' { + it 'Can Get-ADOAgentPool for a given -Organization' -Skip:$IsFork { Get-ADOAgentPool -Organization StartAutomating -PersonalAccessToken $testPat -ErrorAction Stop } @@ -407,7 +413,7 @@ describe 'Calling REST APIs' { } context 'Service Endpoints:' { - it 'Can Get-ADOServiceEndpoint' { + it 'Can Get-ADOServiceEndpoint' -Skip:$IsFork { Get-ADOServiceEndpoint -Organization StartAutomating -Project PSDevOps -PersonalAccessToken $testPat -ErrorAction Stop } @@ -431,7 +437,7 @@ describe 'Calling REST APIs' { } } - context 'Extensions' { + context 'Extensions' -Skip:$IsFork { it 'Can Get-ADOExtension' { Get-ADOExtension -Organization StartAutomating -PersonalAccessToken $testPat -PublisherID ms -ExtensionID feed | Select-Object -First 1 -ExpandProperty PublisherName | @@ -523,7 +529,7 @@ describe 'Calling REST APIs' { } } - it 'Can clear widgets settings within dashboards' { + it 'Can clear widgets settings within dashboards' -Skip:$IsFork { $whatIf = @(Get-ADODashboard -Organization StartAutomating -PersonalAccessToken $testPat -Project PSDevOps -Team 'PSDevOps Team' | Select-Object -First 1 | Get-ADODashboard -Widget | @@ -533,7 +539,7 @@ describe 'Calling REST APIs' { $whatIf.body.settings | Should -Be 'null' } - it 'Can update dashboards' { + it 'Can update dashboards' -Skip:$IsFork { $whatIf = Get-ADODashboard -Organization StartAutomating -PersonalAccessToken $testPat -Project PSDevOps -Team 'PSDevOps Team' | Get-ADODashboard -Widget | Select-Object -First 1 | @@ -546,7 +552,7 @@ describe 'Calling REST APIs' { } } - context 'Service Hooks' { + context 'Service Hooks' -Skip:$IsFork { it 'Can Get Publishers of Service Hooks' { Get-ADOServiceHook -Organization StartAutomating -PersonalAccessToken $testPat -Publisher | Select-Object -First 1 -ExpandProperty ID | @@ -602,7 +608,7 @@ describe 'Calling REST APIs' { } } - context WorkProcesses { + context WorkProcesses -Skip:$IsFork { it 'Can get work procceses related to a project' { Get-ADOProject -Organization StartAutomating -Project PSDevOps -PersonalAccessToken $testPat | Get-ADOWorkProcess | From 5972b5e26f439484b514cb2052a041c54a791706 Mon Sep 17 00:00:00 2001 From: Christopher Boden Date: Wed, 12 May 2021 15:55:56 -0500 Subject: [PATCH 3/4] Corrected skipped tests --- PSDevOps.tests.ps1 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/PSDevOps.tests.ps1 b/PSDevOps.tests.ps1 index a5688c01..974bed4b 100644 --- a/PSDevOps.tests.ps1 +++ b/PSDevOps.tests.ps1 @@ -216,13 +216,13 @@ describe 'Creating Pipelines' { } describe 'Calling REST APIs' { - it 'Can invoke an Azure DevOps REST api' -Skip:$IsFork { + it 'Can invoke an Azure DevOps REST api' { $org = 'StartAutomating' $project = 'PSDevOps' Invoke-ADORestAPI "https://dev.azure.com/$org/$project/_apis/build/builds/?api-version=5.1" -PSTypeName AzureDevOps.Build } - it 'Can Connect to Azure DevOps (Connect-ADO)' { + it 'Can Connect to Azure DevOps (Connect-ADO)' -Skip:$IsFork { $connection = Connect-ADO -Organization StartAutomating -PersonalAccessToken $testPat $connection.Organization | Should -Be StartAutomating } @@ -437,8 +437,8 @@ describe 'Calling REST APIs' { } } - context 'Extensions' -Skip:$IsFork { - it 'Can Get-ADOExtension' { + context 'Extensions' { + it 'Can Get-ADOExtension' -Skip:$IsFork { Get-ADOExtension -Organization StartAutomating -PersonalAccessToken $testPat -PublisherID ms -ExtensionID feed | Select-Object -First 1 -ExpandProperty PublisherName | should -Be Microsoft @@ -452,27 +452,27 @@ describe 'Calling REST APIs' { #> - it 'Can Get-ADOExtension with filters' { + it 'Can Get-ADOExtension with filters' -Skip:$IsFork { Get-ADOExtension -Organization StartAutomating -PersonalAccessToken $testPat -PublisherNameLike Micro* -ExtensionNameLike *feed* -PublisherNameMatch ms -ExtensionNameMatch feed | Select-Object -First 1 -ExpandProperty PublisherName | Should -Be Microsoft } - it 'Can Install-ADOExtension' { + it 'Can Install-ADOExtension' -Skip:$IsFork { $whatIf = Install-ADOExtension -Organization StartAutomating -PublisherID YodLabs -ExtensionID yodlabs-githubstats -WhatIf -PersonalAccessToken $testPat $whatIf.Method | Should -Be POST $whatIf.Uri | Should -BeLike '*/YodLabs/yodlabs-githubstats*' } - it 'Can Uninstall-ADOExtension' { + it 'Can Uninstall-ADOExtension' -Skip:$IsFork { $whatIf = Uninstall-ADOExtension -Organization StartAutomating -PublisherID YodLabs -ExtensionID yodlabs-githubstats -WhatIf -PersonalAccessToken $testPat $whatIf.Method | Should -Be DELETE $whatIf.Uri | Should -BeLike '*/YodLabs/yodlabs-githubstats*' } - it 'Can Enable-ADOExtension' { + it 'Can Enable-ADOExtension' -Skip:$IsFork { $whatIf = Enable-ADOExtension -Organization StartAutomating -PublisherID YodLabs -ExtensionID yodlabs-githubstats -WhatIf -PersonalAccessToken $testPat $whatIf.Method | Should -Be PATCH @@ -480,7 +480,7 @@ describe 'Calling REST APIs' { $whatIf.body.installState.flags | Should -Be none } - it 'Can Disable-ADOExtension' { + it 'Can Disable-ADOExtension' -Skip:$IsFork { $whatIf = Disable-ADOExtension -Organization StartAutomating -PublisherID YodLabs -ExtensionID yodlabs-githubstats -WhatIf -PersonalAccessToken $testPat $whatIf.Method | Should -Be PATCH @@ -490,7 +490,7 @@ describe 'Calling REST APIs' { - it 'Get Get-ADOTask' { + it 'Get Get-ADOTask' -Skip:$IsFork { Get-ADOTask -Organization StartAutomating -PersonalAccessToken $testPat | Select-Object -First 1 -ExpandProperty PSTypenames | Select-Object -Last 1 | From 367904e6faafc8d637e6054fea0b655ac1bb6d3f Mon Sep 17 00:00:00 2001 From: Christopher Boden Date: Wed, 12 May 2021 16:13:11 -0500 Subject: [PATCH 4/4] Moved skip from context to it --- PSDevOps.tests.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/PSDevOps.tests.ps1 b/PSDevOps.tests.ps1 index 974bed4b..9a3a3844 100644 --- a/PSDevOps.tests.ps1 +++ b/PSDevOps.tests.ps1 @@ -552,13 +552,13 @@ describe 'Calling REST APIs' { } } - context 'Service Hooks' -Skip:$IsFork { - it 'Can Get Publishers of Service Hooks' { + context 'Service Hooks' { + it 'Can Get Publishers of Service Hooks' -Skip:$IsFork { Get-ADOServiceHook -Organization StartAutomating -PersonalAccessToken $testPat -Publisher | Select-Object -First 1 -ExpandProperty ID | Should -be Audit } - it 'Can Get Consumers of Service Hooks' { + it 'Can Get Consumers of Service Hooks' -Skip:$IsFork { Get-ADOServiceHook -Organization StartAutomating -PersonalAccessToken $testPat -Consumer | Select-Object -First 1 -ExpandProperty ID | Should -be appVeyor @@ -608,15 +608,15 @@ describe 'Calling REST APIs' { } } - context WorkProcesses -Skip:$IsFork { - it 'Can get work procceses related to a project' { + context WorkProcesses { + it 'Can get work procceses related to a project' -Skip:$IsFork { Get-ADOProject -Organization StartAutomating -Project PSDevOps -PersonalAccessToken $testPat | Get-ADOWorkProcess | Select-Object -ExpandProperty Name | should -Be 'StartAutomating Basic' } - it 'Can get work item types related to a process' { + it 'Can get work item types related to a process' -Skip:$IsFork { Get-ADOProject -Organization StartAutomating -Project PSDevOps -PersonalAccessToken $testPat | Get-ADOWorkProcess | Get-ADOWorkItemType | @@ -624,7 +624,7 @@ describe 'Calling REST APIs' { should -Be issue } - it 'Can create new work item types' { + it 'Can create new work item types' -Skip:$IsFork { $whatIfResult = Get-ADOProject -Organization StartAutomating -Project PSDevOps -PersonalAccessToken $testPat | Get-ADOWorkProcess | @@ -634,7 +634,7 @@ describe 'Calling REST APIs' { should -Be icon_flame } - it 'Can remove custom work item types' { + it 'Can remove custom work item types' -Skip:$IsFork { $whatIfResult = Get-ADOProject -Organization StartAutomating -Project PSDevOps -PersonalAccessToken $testPat | Get-ADOWorkProcess |