diff --git a/CHANGELOG.md b/CHANGELOG.md index b61960887..77e350d80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,11 @@ ## 7.1.3 -Added Clear-VSTeamDefaultProjectCount and Set-VSTeamDefaultProjectCount to control the default number of projects returned for tab completion and validation. By default only 100 projects are returned and the 100 returned is nondeterministic. But calling Set-VSTeamDefaultProjectCount you can increase the number of projects returned. +Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/350) from [Daniel Silva](https://github.com/DanielSSilva) which included the following: + +- Fixed exception thrown by the Update-VSTeamPullRequest when status is set to "completed", by adding the missing "lastMergeSourceCommit" property to body. + +Also added Clear-VSTeamDefaultProjectCount and Set-VSTeamDefaultProjectCount to control the default number of projects returned for tab completion and validation. By default only 100 projects are returned and the 100 returned is nondeterministic. But calling Set-VSTeamDefaultProjectCount you can increase the number of projects returned. ## 7.1.2 diff --git a/Source/Public/Update-VSTeamPullRequest.ps1 b/Source/Public/Update-VSTeamPullRequest.ps1 index 1d4de06ff..e23c27e96 100644 --- a/Source/Public/Update-VSTeamPullRequest.ps1 +++ b/Source/Public/Update-VSTeamPullRequest.ps1 @@ -1,6 +1,6 @@ function Update-VSTeamPullRequest { [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "High", DefaultParameterSetName = 'Draft', - HelpUri='https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Update-VSTeamPullRequest')] + HelpUri = 'https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Update-VSTeamPullRequest')] param( [Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true, Position = 0)] [Alias('Id')] @@ -46,7 +46,13 @@ function Update-VSTeamPullRequest { } if ($Status) { - $body = '{"status": "' + $Status + '"}' + if ($Status -eq "completed") { + $lastMergeSourceCommit = Get-VSTeamPullRequest -RepositoryId $RepositoryId | Where-Object { $_.pullRequestId -eq $PullRequestId } | Select-Object -ExpandProperty lastMergeSourceCommit | ConvertTo-Json + $body = '{"status": "' + $Status + '", "lastMergeSourceCommit": ' + $lastMergeSourceCommit + '}' + } + else { + $body = '{"status": "' + $Status + '"}' + } } # Call the REST API diff --git a/Source/VSTeam.psd1 b/Source/VSTeam.psd1 index d960375bf..3a7f064ce 100644 --- a/Source/VSTeam.psd1 +++ b/Source/VSTeam.psd1 @@ -12,7 +12,7 @@ RootModule = 'VSTeam.psm1' # Version number of this module. - ModuleVersion = '7.1.2' + ModuleVersion = '7.1.3' # Supported PSEditions CompatiblePSEditions = @('Core', 'Desktop') diff --git a/Tests/function/tests/Update-VSTeamPullRequest.Tests.ps1 b/Tests/function/tests/Update-VSTeamPullRequest.Tests.ps1 index 7593ccb80..bc13723f0 100644 --- a/Tests/function/tests/Update-VSTeamPullRequest.Tests.ps1 +++ b/Tests/function/tests/Update-VSTeamPullRequest.Tests.ps1 @@ -3,15 +3,17 @@ Set-StrictMode -Version Latest Describe 'VSTeamPullRequest' { BeforeAll { . "$PSScriptRoot\_testInitialize.ps1" $PSCommandPath + . "$baseFolder/Source/Public/Get-VSTeamPullRequest.ps1" . "$baseFolder/Source/Public/Get-VSTeamUser.ps1" Mock _getInstance { return 'https://dev.azure.com/test' } Mock _getApiVersion { return '1.0-unitTest' } -ParameterFilter { - $Service -eq 'Git' -or + $Service -eq 'Git' -or $Service -eq 'Graph' } Mock Invoke-RestMethod { Open-SampleFile 'users.single.json' } + Mock Get-VSTeamPullRequest { Open-SampleFile 'Get-VSTeamPullRequest-Id_17.json' } Mock Invoke-RestMethod { Open-SampleFile 'updatePullRequestResponse.json' } -ParameterFilter { $PullRequestId -eq 18000 } @@ -57,6 +59,20 @@ Describe 'VSTeamPullRequest' { } } + It 'Update-VSTeamPullRequest to set status to completed' { + ## Act + Update-VSTeamPullRequest -RepositoryId "45df2d67-e709-4557-a7f9-c6812b449277" -PullRequestId 17 -Status completed -Force + + ## Assert + Should -Invoke Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter { + $Method -eq 'Patch' -and + $Uri -like "*repositories/45df2d67-e709-4557-a7f9-c6812b449277/*" -and + $Uri -like "*pullrequests/17*" -and + $Body -like '*"status": "completed"*' -and + $Body -like '*"commitId":*"c8262543095d0d443b5bcaff27201ef01314d4ff"*' + } + } + It 'Update-VSTeamPullRequest to set to enable auto complete' { ## Arrange $user = Get-VSTeamUser -Descriptor "aad.OTcyOTJkNzYtMjc3Yi03OTgxLWIzNDMtNTkzYmM3ODZkYjlj" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cab3ac481..516fb7dab 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,7 +9,7 @@ resources: variables: Folder: 'dist' TEAM_CIBUILD: 'true' - PESTER_VERSION: '5.0.2' + PESTER_VERSION: '5.1.1' stages: - stage: Build