Skip to content

Commit

Permalink
Check link against the SHA commits
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu committed Aug 14, 2020
1 parent 4ceb21e commit fd83444
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion eng/common/pipelines/templates/steps/verify-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 12 additions & 1 deletion eng/common/scripts/Verify-Links.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit fd83444

Please sign in to comment.