Skip to content

Commit b34b0ca

Browse files
sima-zhuazure-sdk
authored andcommitted
Fix bugs
1 parent 759862e commit b34b0ca

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

eng/common/scripts/get-markdown-files-from-changed-files.ps1

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
param (
22
# The root repo we scaned with.
3-
[string[]] $RootRepo
3+
[string[]] $RootRepo = "./"
44
)
55
$deletedFiles = (git diff origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH} HEAD --name-only --diff-filter=D)
66
$renamedFiles = (git diff origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH} HEAD --diff-filter=R)
77
$changedMarkdowns = (git diff origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH} HEAD --name-only -- '*.md')
8-
# Removed the deleted markdowns.
9-
$changedMarkdowns = $changedMarkdowns |Where-Object { $deletedFiles -notcontains $_ }
8+
# These are for local testing.
9+
# $deletedFiles = (git diff origin/master HEAD --name-only --diff-filter=D)
10+
# $renamedFiles = (git diff origin/master HEAD --diff-filter=R)
11+
# $changedMarkdowns = (git diff origin/master HEAD --name-only -- '*.md')
1012

1113
$beforeRenameFiles = @()
1214
# Retrieve the renamed from files.
@@ -16,15 +18,18 @@ foreach($file in $renamedFiles) {
1618
}
1719
}
1820
# A combined list of deleted and renamed files.
19-
$relativePathLinks += ($deletedFiles + $beforeRenameFiles)
20-
21+
$relativePathLinks = ($deletedFiles + $beforeRenameFiles)
22+
# Removed the deleted markdowns.
23+
$changedMarkdowns = $changedMarkdowns | Where-Object { $relativePathLinks -notcontains $_ }
2124
# Scan all markdowns and find if it contains the deleted or renamed files.
2225
$markdownContainLinks = @()
23-
foreach ($f in (Get-ChildItem -Path $RootRepo -Recurse -Include *.md)) {
24-
$content = Get-Content -Path $f -Raw
25-
foreach($l in $fullPathLinks) {
26+
$allMarkdownFiles = Get-ChildItem -Path $RootRepo -Recurse -Include *.md
27+
foreach ($f in $allMarkdownFiles) {
28+
$filePath = $f.ToString()
29+
$content = Get-Content -Path $filePath -Raw
30+
foreach($l in $relativePathLinks) {
2631
if ($content -match $l) {
27-
$markdownContainLinks += $f
32+
$markdownContainLinks += $filePath
2833
break
2934
}
3035
}

0 commit comments

Comments
 (0)