Unverified Commit bb38fe5f authored by Delba de Oliveira's avatar Delba de Oliveira Committed by GitHub

[Docs] Update link validator: use checks, fail on PR from forked repo (#51706)

parent b7d49e0e
...@@ -325,24 +325,52 @@ const formatTableRow = (link: string, docPath: string) => { ...@@ -325,24 +325,52 @@ const formatTableRow = (link: string, docPath: string) => {
return `| ${link} | [/${docPath}](https://github.com/vercel/next.js/blob/${sha}/${docPath}) | \n` return `| ${link} | [/${docPath}](https://github.com/vercel/next.js/blob/${sha}/${docPath}) | \n`
} }
async function createCommitStatus( async function updateCheckStatus(
errorsExist: boolean, errorsExist: boolean,
commentUrl?: string commentUrl?: string
): Promise<void> { ): Promise<void> {
const state = errorsExist ? 'failure' : 'success' const isFork = pullRequest.head.repo.fork
const description = errorsExist const checkName = 'Docs Link Validation'
? 'This PR introduces broken links to the docs. Click details for a list.'
: 'All broken links are now fixed, thank you!'
await octokit.rest.repos.createCommitStatus({ let summary, text
if (errorsExist) {
summary =
'This PR introduces broken links to the docs. Click details for a list.'
text = `[See the comment for details](${commentUrl})`
} else {
summary = 'No broken links found'
}
const checkParams = {
owner, owner,
repo, repo,
sha, name: checkName,
state, head_sha: sha,
description, status: 'completed',
context: 'Link Validation', conclusion: errorsExist ? 'failure' : 'success',
target_url: commentUrl, output: {
}) title: checkName,
summary: summary,
text: text,
},
}
if (isFork) {
if (errorsExist) {
setFailed(
'This PR introduces broken links to the docs. The action could not create a Github check because it is initiated from a forked repo.'
)
} else {
console.log('Link validation was successful.')
}
} else {
try {
await octokit.rest.checks.create(checkParams)
} catch (error) {
setFailed('Failed to create check: ' + error)
}
}
} }
// Main function that triggers link validation across .mdx files // Main function that triggers link validation across .mdx files
...@@ -439,9 +467,9 @@ async function validateAllInternalLinks(): Promise<void> { ...@@ -439,9 +467,9 @@ async function validateAllInternalLinks(): Promise<void> {
} }
try { try {
await createCommitStatus(errorsExist, commentUrl) await updateCheckStatus(errorsExist, commentUrl)
} catch (error) { } catch (error) {
setFailed('Failed to create commit status: ' + error) setFailed('Failed to create Github check: ' + error)
} }
} catch (error) { } catch (error) {
setFailed('Error validating internal links: ' + error) setFailed('Error validating internal links: ' + error)
......
name: 'validate-docs-links' name: 'Validate Doc Links'
on: on:
pull_request: pull_request:
paths: paths:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment