Skip to content

Commit

Permalink
Have default value for helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu authored and azure-sdk committed Mar 15, 2022
1 parent 11c6c73 commit 11b089c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 36 deletions.
2 changes: 1 addition & 1 deletion eng/common/pipelines/templates/steps/credscan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ steps:
# Add config to disable the quote and encoding on file name.
# Ref: https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support#disable-quoted-file-names
# Ref: https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support#disable-commit-message-transcoding
$changedFiles = & 'eng/common/scripts/get-diff-changes-from-PR.ps1'
$changedFiles = & 'eng/common/scripts/get-diff-changes.ps1'
$changedFiles | ForEach-Object { Add-Content -Path "${{ parameters.SourceDirectory }}/credscan.tsv" -Value "${{ parameters.SourceDirectory }}/$_"}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-eng/common")) -and $targetBranch -eq $defaultBranch)
{
$filesInCommonDir = & 'eng/common/scripts/get-diff-changes-from-PR.ps1' -DiffPath 'eng/common/*'
$filesInCommonDir = & 'eng/common/scripts/get-diff-changes.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}"
Expand Down
41 changes: 8 additions & 33 deletions eng/common/scripts/get-diff-changes-from-PR.ps1
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
<#
.SYNOPSIS
Returns git diff changes in pull request.
.DESCRIPTION
The script is to return diff changes in pull request.
.PARAMETER SourceCommittish
The branch committish PR merges from.
Definition of committish: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefcommit-ishacommit-ishalsocommittish
.PARAMETER TargetCommittish
The branch committish PR targets to merge into.
.PARAMETER DiffPath
The files which git diff to scan against. Support regex match. E.g. "eng/common/*", "*.md"
.PARAMETER DiffFilterType
The filter type A(a)dd, D(d)elete, R(r)ename, U(u)pate.
E.g. 'ad' means filter out the newly added file and deleted file
E.g. '' means no filter on file mode.
#>
[CmdletBinding()]
param (
[string] $SourceCommittish = "${env:BUILD_SOURCEVERSION}",
[string] $TargetCommittish = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "refs/heads/"),
[string] $DiffPath = "",
[string] $DiffFilterType = 'd'
)

#Set-StrictMode -Version 3

function Get-PullRequest-Diff-Changes($SourceCommittish, $TargetCommittish, $DiffPath, $DiffFilterType) {
function Get-PullRequest-Diff-Changes {
param (
[string]$SourceCommittish= "${env:BUILD_SOURCEVERSION}",
[string]$TargetCommittish = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "refs/heads/"),
[string]$DiffPath,
[string]$DiffFilterType = "d"
)
# If ${env:SYSTEM_PULLREQUEST_TARGETBRANCH} is empty, then return empty.
if ($TargetCommittish -eq "origin/") {
Write-Host "There is no target branch passed in. "
return ""
}

# Git PR diff: https://docs.github.com/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests#three-dot-and-two-dot-git-diff-comparisons
$command = "git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff `"$TargetCommittish...HEAD`" --name-only --diff-filter=$DiffFilterType"
$command = "git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff `"$TargetCommittish...$SourceCommittish`" --name-only --diff-filter=$DiffFilterType"
if ($DiffPath) {
$command = $command + " -- `'$DiffPath`'"
}
Expand All @@ -50,8 +30,3 @@ function Get-PullRequest-Diff-Changes($SourceCommittish, $TargetCommittish, $Dif
}
return $changedFiles
}

return Get-PullRequest-Diff-Changes -SourceCommittish $SourceCommittish `
-TargetCommittish $TargetCommittish `
-DiffPath $DiffPath `
-DiffFilterType $DiffFilterType
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ param (
[string] $targetBranch = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "/refs/heads/")
)

. (Join-Path $PSScriptRoot get-diff-changes-from-PR.ps1)
. (Join-Path $PSScriptRoot common.ps1)

return Get-PullRequest-Diff-Changes -TargetCommittish $targetBranch -DiffPath '*.md'

0 comments on commit 11b089c

Please sign in to comment.