Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu authored and azure-sdk committed Nov 7, 2020
1 parent 46a1580 commit 8c1e857
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions eng/common/scripts/get-markdown-files-from-changed-files.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
param (
# The root repo we scaned with.
[string[]] $RootRepo
[string[]] $RootRepo = "./"
)
$deletedFiles = (git diff origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH} HEAD --name-only --diff-filter=D)
$renamedFiles = (git diff origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH} HEAD --diff-filter=R)
$changedMarkdowns = (git diff origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH} HEAD --name-only -- '*.md')
# Removed the deleted markdowns.
$changedMarkdowns = $changedMarkdowns |Where-Object { $deletedFiles -notcontains $_ }
# These are for local testing.
# $deletedFiles = (git diff origin/master HEAD --name-only --diff-filter=D)
# $renamedFiles = (git diff origin/master HEAD --diff-filter=R)
# $changedMarkdowns = (git diff origin/master HEAD --name-only -- '*.md')

$beforeRenameFiles = @()
# Retrieve the renamed from files.
Expand All @@ -16,15 +18,18 @@ foreach($file in $renamedFiles) {
}
}
# A combined list of deleted and renamed files.
$relativePathLinks += ($deletedFiles + $beforeRenameFiles)

$relativePathLinks = ($deletedFiles + $beforeRenameFiles)
# Removed the deleted markdowns.
$changedMarkdowns = $changedMarkdowns | Where-Object { $relativePathLinks -notcontains $_ }
# Scan all markdowns and find if it contains the deleted or renamed files.
$markdownContainLinks = @()
foreach ($f in (Get-ChildItem -Path $RootRepo -Recurse -Include *.md)) {
$content = Get-Content -Path $f -Raw
foreach($l in $fullPathLinks) {
$allMarkdownFiles = Get-ChildItem -Path $RootRepo -Recurse -Include *.md
foreach ($f in $allMarkdownFiles) {
$filePath = $f.ToString()
$content = Get-Content -Path $filePath -Raw
foreach($l in $relativePathLinks) {
if ($content -match $l) {
$markdownContainLinks += $f
$markdownContainLinks += $filePath
break
}
}
Expand Down

0 comments on commit 8c1e857

Please sign in to comment.