Skip to content

Commit

Permalink
Fix regex applying PR logic to versioned release branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
naeemkhedarun committed May 9, 2017
1 parent 9974ce8 commit bc79131
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
38 changes: 38 additions & 0 deletions VstsPullRequestApprover/VstsPullRequestApprover.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,42 @@ Describe "Get-VstsApiBaseUri" {
}
}

Describe "Get-PullRequestId" {
InModuleScope VstsPullRequestApprover {
Context "When called with a valid pull request branch" {
$id = Get-PullRequestId "refs/pull/861/merge"

It "Should return the id" {
$id | Should Be "861"
}
}

Context "When called with a versioned branch" {
$id = Get-PullRequestId "refs/head/release/1.0.0"

It "Should return null" {
$id | Should Be $null
}
}

Context "When called with a unversioned branch" {
$id = Get-PullRequestId "refs/head/develop"

It "Should return null" {
$id | Should Be $null
}
}


Context "When called with a feature branch" {
$id = Get-PullRequestId "refs/head/feature/12321-new-feature"

It "Should return null" {
$id | Should Be $null
}
}
}
}


Remove-Module VstsPullRequestApprover
12 changes: 11 additions & 1 deletion VstsPullRequestApprover/VstsPullRequestApprover.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,23 @@ function Get-VstsApiBaseUri
return "https://$($variables.Instance)/$($variables.TeamProject)/_apis/git/repositories/$($variables.Repository)"
}

function Get-PullRequestId
{
param($branch)

return $branch | select-string -Pattern "refs/pull/(?<id>[0-9]+)/merge" `
| Select-Object -ExpandProperty Matches `
| ForEach-Object { $_.Groups["id"].Value } `
| Select-Object -First 1
}

function Set-PullRequestStatus
{
param($vcsroot, $branch, $accessToken, $reviewerAccount, [bool]$approve, $buildUri)

Write-Host "**** Setting build status for pull request ****"

$pullRequest = ($branch | select-string -Pattern "([0-9]+)").Matches.Value
$pullRequest = Get-PullRequestId $branch

if(!$pullRequest)
{
Expand Down

0 comments on commit bc79131

Please sign in to comment.