45
45
. PARAMETER outputCacheFile
46
46
Path to a file that the script will output all the validated links after running all checks.
47
47
48
+ . PARAMETER localGithubClonedRoot
49
+ Path to the root of a local github clone. This is used to resolve links to local files in the repo instead of making web requests.
50
+
51
+ . PARAMETER localBuildRepoName
52
+ The name of the repo that is being built. This is used to resolve links to local files in the repo instead of making web requests.
53
+
54
+ . PARAMETER localBuildRepoPath
55
+ The path to the local build repo. This is used to resolve links to local files in the repo instead of making web requests.
56
+
48
57
. PARAMETER requestTimeoutSec
49
58
The number of seconds before we timeout when sending an individual web request. Default is 15 seconds.
50
59
@@ -73,7 +82,9 @@ param (
73
82
[string ] $inputCacheFile ,
74
83
[string ] $outputCacheFile ,
75
84
[string ] $localGithubClonedRoot = " " ,
76
- [string ] $requestTimeoutSec = 15
85
+ [string ] $localBuildRepoName = " " ,
86
+ [string ] $localBuildRepoPath = " " ,
87
+ [string ] $requestTimeoutSec = 15
77
88
)
78
89
79
90
Set-StrictMode - Version 3.0
@@ -82,8 +93,17 @@ $ProgressPreference = "SilentlyContinue"; # Disable invoke-webrequest progress d
82
93
83
94
function ProcessLink ([System.Uri ]$linkUri ) {
84
95
# To help improve performance and rate limiting issues with github links we try to resolve them based on a local clone if one exists.
85
- if ($localGithubClonedRoot -and $linkUri -match ' ^https://github.com/Azure/(?<repo>[^/]+)/(?:blob|tree)/(main|.*_[^/]+|.*/v[^/]+)/(?<path>.*)$' ) {
86
- $localPath = Join-Path $localGithubClonedRoot $matches [' repo' ] $matches [' path' ]
96
+ if (($localGithubClonedRoot -or $localBuildRepoName ) -and $linkUri -match ' ^https://github.com/(?<org>Azure)/(?<repo>[^/]+)/(?:blob|tree)/(main|.*_[^/]+|.*/v[^/]+)/(?<path>.*)$' ) {
97
+
98
+ if ($localBuildRepoName -eq ($matches [' org' ] + " /" + $matches [' repo' ])) {
99
+ # If the link is to the current repo, use the local build path
100
+ $localPath = Join-Path $localBuildRepoPath $matches [' path' ]
101
+ }
102
+ else {
103
+ # Otherwise use the local github clone path
104
+ $localPath = Join-Path $localGithubClonedRoot $matches [' repo' ] $matches [' path' ]
105
+ }
106
+
87
107
if (Test-Path $localPath ) {
88
108
return $true
89
109
}
@@ -165,7 +185,7 @@ $emptyLinkMessage = "There is at least one empty link in the page. Please replac
165
185
if (! $userAgent ) {
166
186
$userAgent = " Chrome/87.0.4280.88"
167
187
}
168
- function NormalizeUrl ([string ]$url ){
188
+ function NormalizeUrl ([string ]$url ) {
169
189
if (Test-Path $url ) {
170
190
$url = " file://" + (Resolve-Path $url ).ToString();
171
191
}
0 commit comments