Skip to content

Commit

Permalink
Merge branch 'canary' into hrmny/typecheck-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Jun 23, 2023
2 parents caa3987 + 889e220 commit a36f53e
Show file tree
Hide file tree
Showing 48 changed files with 1,594 additions and 884 deletions.
2 changes: 1 addition & 1 deletion .github/actions/validate-docs-links/lib/index.js

Large diffs are not rendered by default.

56 changes: 42 additions & 14 deletions .github/actions/validate-docs-links/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,24 +325,52 @@ const formatTableRow = (link: string, docPath: string) => {
return `| ${link} | [/${docPath}](https://github.com/vercel/next.js/blob/${sha}/${docPath}) | \n`
}

async function createCommitStatus(
async function updateCheckStatus(
errorsExist: boolean,
commentUrl?: string
): Promise<void> {
const state = errorsExist ? 'failure' : 'success'
const description = errorsExist
? 'This PR introduces broken links to the docs. Click details for a list.'
: 'All broken links are now fixed, thank you!'
const isFork = pullRequest.head.repo.fork
const checkName = 'Docs Link Validation'

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,
repo,
sha,
state,
description,
context: 'Link Validation',
target_url: commentUrl,
})
name: checkName,
head_sha: sha,
status: 'completed',
conclusion: errorsExist ? 'failure' : 'success',
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
Expand Down Expand Up @@ -439,9 +467,9 @@ async function validateAllInternalLinks(): Promise<void> {
}

try {
await createCommitStatus(errorsExist, commentUrl)
await updateCheckStatus(errorsExist, commentUrl)
} catch (error) {
setFailed('Failed to create commit status: ' + error)
setFailed('Failed to create Github check: ' + error)
}
} catch (error) {
setFailed('Error validating internal links: ' + error)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-docs-links.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'validate-docs-links'
name: 'Validate Doc Links'
on:
pull_request:
paths:
Expand Down

0 comments on commit a36f53e

Please sign in to comment.