diff --git a/eng/common/pipelines/templates/steps/verify-links.yml b/eng/common/pipelines/templates/steps/verify-links.yml index a3d385becef..cb10de3a828 100644 --- a/eng/common/pipelines/templates/steps/verify-links.yml +++ b/eng/common/pipelines/templates/steps/verify-links.yml @@ -11,4 +11,10 @@ steps: workingDirectory: $(Build.SourcesDirectory)/${{ parameters.Directory }} filePath: eng/common/scripts/Verify-Links.ps1 arguments: > - -urls $(dir -r -i *.md) -rootUrl "file://$(Build.SourcesDirectory)/${{ parameters.Directory }}" -recursive:$false -ignoreLinksFile ${{ parameters.IgnoreLinksFile }} + -urls $(dir -r -i *.md) + -rootUrl "file://$(Build.SourcesDirectory)/${{ parameters.Directory }}" + -recursive:$false + -ignoreLinksFile ${{ parameters.IgnoreLinksFile }} + -sourceCommit $(system.pullRequest.sourceCommitId) + -sourceRepoUrl $(System.PullRequest.sourceRepositoryUri) + \ No newline at end of file diff --git a/eng/common/scripts/Verify-Links.ps1 b/eng/common/scripts/Verify-Links.ps1 index 5da025f9d65..7efbe17e6c6 100644 --- a/eng/common/scripts/Verify-Links.ps1 +++ b/eng/common/scripts/Verify-Links.ps1 @@ -14,7 +14,11 @@ param ( # list of http status codes count as broken links. Defaults to 400, 401, 404, SocketError.HostNotFound = 11001, SocketError.NoData = 11004 [array] $errorStatusCodes = @(400, 401, 404, 11001, 11004), # flag to allow resolving relative paths or not - [bool] $resolveRelativeLinks = $true + [bool] $resolveRelativeLinks = $true, + # development repo owner from pr + [string] $sourceCommit = "", + # development repo branch from pr + [string] $sourceRepoUrl = "" ) $ProgressPreference = "SilentlyContinue"; # Disable invoke-webrequest progress dialog @@ -167,6 +171,11 @@ function CheckLink ([System.Uri]$linkUri) } $checkedLinks[$linkUri] = $true; } +$GithubRegex = "($sourceRepoUrl/blob/)(\w+)(/.*)" +$ReplacementPattern = "`${1}$sourceCommit`$3" +function ReplaceGithubLink([string]$originLink) { + return $originLink -replace $GithubRegex, $ReplacementPattern +} function GetLinks([System.Uri]$pageUri) { @@ -245,6 +254,8 @@ while ($pageUrisToCheck.Count -ne 0) Write-Host "Found $($linkUris.Count) links on page $pageUri"; foreach ($linkUri in $linkUris) { + $linkUri = ReplaceGithubLink $linkUri + CheckLink $linkUri if ($recursive) { if ($linkUri.ToString().StartsWith($baseUrl) -and !$checkedPages.ContainsKey($linkUri)) {