fix the target branch checking (#3474)

This commit is contained in:
Azure SDK Bot 2022-03-24 14:52:26 -07:00 committed by GitHub
parent 835f156af9
commit 6f426df9f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -8,11 +8,10 @@ steps:
- pwsh: |
# Find the default branch of the repo. The variable value sets in build step.
Write-Host "Default Branch: $(DefaultBranch)"
$targetBranch = "$(System.PullRequest.TargetBranch)" -replace "refs/heads/"
if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-eng/common")) -and $targetBranch -eq "$(DefaultBranch)")
if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-eng/common")) -and "$(System.PullRequest.TargetBranch)" -match "^(refs/heads/)?$(DefaultBranch)$")
{
$filesInCommonDir = & "eng/common/scripts/get-changedfiles.ps1" -TargetCommittish $targetBranch -DiffPath 'eng/common/*'
$filesInCommonDir = & "eng/common/scripts/get-changedfiles.ps1" -DiffPath 'eng/common/*'
if (($LASTEXITCODE -eq 0) -and ($filesInCommonDir.Count -gt 0))
{
Write-Host "##vso[task.LogIssue type=error;]Changes to files under 'eng/common' directory should not be made in this Repo`n${filesInCommonDir}"

View File

@ -10,7 +10,7 @@ function Get-ChangedFiles {
[string]$DiffFilterType = "d"
)
# If ${env:SYSTEM_PULLREQUEST_TARGETBRANCH} is empty, then return empty.
if ($TargetCommittish -eq "origin/") {
if (!$TargetCommittish -or ($TargetCommittish -eq "origin/")) {
Write-Host "There is no target branch passed in. "
return ""
}