-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use common script for git diff changes
- Loading branch information
Showing
10 changed files
with
114 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
function Get-ChangedFiles { | ||
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 "" | ||
} | ||
|
||
# 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 | ||
# 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...$SourceCommittish`" --name-only --diff-filter=$DiffFilterType" | ||
if ($DiffPath) { | ||
$command = $command + " -- `'$DiffPath`'" | ||
} | ||
Write-Host $command | ||
$changedFiles = Invoke-Expression -Command $command | ||
if(!$changedFiles) { | ||
Write-Host "No changed files in git diff between $TargetCommittish and $SourceCommittish" | ||
} | ||
else { | ||
Write-Host "Here are the diff files:" | ||
foreach ($file in $changedFiles) { | ||
Write-Host " $file" | ||
} | ||
} | ||
return $changedFiles | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
<# | ||
.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 | ||
. (Join-Path $PSScriptRoot common.ps1) | ||
|
||
return Get-ChangedFiles -SourceCommittish $SourceCommittish ` | ||
-TargetCommittish $TargetCommittish ` | ||
-DiffPath $DiffPath ` | ||
-DiffFilterType $DiffFilterType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
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...$SourceCommittish`" --name-only --diff-filter=$DiffFilterType" | ||
if ($DiffPath) { | ||
$command = $command + " -- `'$DiffPath`'" | ||
} | ||
Write-Host $command | ||
$changedFiles = Invoke-Expression -Command $command | ||
if(!$changedFiles) { | ||
Write-Host "No changed files in git diff between $TargetCommittish and $SourceCommittish" | ||
} | ||
else { | ||
Write-Host "Here are the diff files:" | ||
foreach ($file in $changedFiles) { | ||
Write-Host " $file" | ||
} | ||
} | ||
return $changedFiles | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.