forked from Azure/azure-sdk-for-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync eng/common directory with azure-sdk-tools repository for Tools PR …
- Loading branch information
Showing
8 changed files
with
117 additions
and
55 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
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
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,54 @@ | ||
param ( | ||
# url list to verify links. Can either be a http address or a local file request. Local file paths support md and html files. | ||
[string] $sourceDir, | ||
# file that contains a set of links to ignore when verifying | ||
[string] $ignoreLinksFile = "$PSScriptRoot/ignore-links.txt", | ||
# switch that will enable devops specific logging for warnings | ||
[switch] $devOpsLogging = $false, | ||
[string] $branchReplaceRegex = "(https://github.com/.*/(?:blob|tree)/)master(/.*)", | ||
# the substitute branch name or SHA commit | ||
[string] $releaseTag = "" | ||
) | ||
|
||
$regexOptions = [System.Text.RegularExpressions.RegexOptions]"Singleline, IgnoreCase"; | ||
|
||
function ReplaceLink ($scanFolder, $fileSuffix, $replacement, $customRegex) { | ||
$regex = new-object System.Text.RegularExpressions.Regex ($branchReplaceRegex, $regexOptions) | ||
if ($customRegex) { | ||
$regex = new-object System.Text.RegularExpressions.Regex ($customRegex, $regexOptions) | ||
} | ||
if (!$fileSuffix) { | ||
Write-Error "Please provide at least one file extension to scan against." | ||
} | ||
$replacementPattern = "`${2}$replacement`$3" | ||
if (!$replacement) { | ||
Write-Error "Please provide the replacement string to replace with." | ||
} | ||
if ($scanFolder) { | ||
$fileSuffixArray = $fileSuffix -split "," | ||
$url = @() | ||
|
||
foreach ($fileExtension in $fileSuffixArray) { | ||
$fileRegex = "*" + $fileSuffix.Trim() | ||
$urls += Get-ChildItem -Path "$scanFolder/*" -Recurse -Include $fileRegex | ||
} | ||
|
||
if ($urls.Count -eq 0) { | ||
Write-Host "Usage $($MyInvocation.MyCommand.Name) <urls>"; | ||
return; | ||
} | ||
$needTochange = @{} | ||
foreach ($url in $urls) { | ||
while ((Get-Content -Path $url) -match $regex) { | ||
Write-Verbose "We have master link matches in page $url" | ||
$needTochange[$url] = $true | ||
(Get-Content -Path $url) -replace $regex, $replacementPattern | Set-Content -Path $url | ||
} | ||
} | ||
foreach ($page in $needTochange.Keys) { | ||
Write-Host "There are replacements in page $page" | ||
} | ||
} | ||
} | ||
|
||
#ReplaceLink -scanFolder $sourceDir -replacement $releaseTag -fileSuffix ".html" |
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