Skip to content

Commit

Permalink
Fix exception caused by Update-VSTeamPullRequest with -Status "comple…
Browse files Browse the repository at this point in the history
…ted" (#380)

* Fixed exception for when status is set to completed.

* removed the space

* edited changelog

* Added tests for Update-VSTeamPullRequest

* Updated version and change log.

Co-authored-by: Daniel Silva <[email protected]>
Co-authored-by: Donovan Brown <[email protected]>
  • Loading branch information
3 people authored Feb 20, 2021
1 parent 9f6808d commit 41ff4c0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions Source/Public/Update-VSTeamPullRequest.ps1
Original file line number Diff line number Diff line change
@@ -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')]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Source/VSTeam.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
18 changes: 17 additions & 1 deletion Tests/function/tests/Update-VSTeamPullRequest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resources:
variables:
Folder: 'dist'
TEAM_CIBUILD: 'true'
PESTER_VERSION: '5.0.2'
PESTER_VERSION: '5.1.1'

stages:
- stage: Build
Expand Down

0 comments on commit 41ff4c0

Please sign in to comment.