Unverified Commit 48375e49 authored by Steven's avatar Steven Committed by GitHub

chore(ci): fix validate-docs-links for non-PR (#53129)

This PR fixes an issue when `validate-docs-links` is run on a branch
like `canary` instead of a branch from a PR.

Example error message:


https://github.com/vercel/next.js/actions/runs/5649063425/job/15302604957
parent 8dede2a4
...@@ -59,8 +59,14 @@ const COMMENT_TAG = '<!-- LINK_CHECKER_COMMENT -->' ...@@ -59,8 +59,14 @@ const COMMENT_TAG = '<!-- LINK_CHECKER_COMMENT -->'
const { context, getOctokit } = github const { context, getOctokit } = github
const octokit = getOctokit(process.env.GITHUB_TOKEN!) const octokit = getOctokit(process.env.GITHUB_TOKEN!)
const { owner, repo } = context.repo const { owner, repo } = context.repo
const pullRequest = context.payload.pull_request! const pullRequest = context.payload.pull_request
if (!pullRequest) {
console.log('Skipping since this is not a pull request')
process.exit(0)
}
const sha = pullRequest.head.sha const sha = pullRequest.head.sha
const isFork = pullRequest.head.repo.fork
const prNumber = pullRequest.number
const slugger = new GithubSlugger() const slugger = new GithubSlugger()
...@@ -280,7 +286,7 @@ async function findBotComment(): Promise<Comment | undefined> { ...@@ -280,7 +286,7 @@ async function findBotComment(): Promise<Comment | undefined> {
const { data: comments } = await octokit.rest.issues.listComments({ const { data: comments } = await octokit.rest.issues.listComments({
owner, owner,
repo, repo,
issue_number: pullRequest.number, issue_number: prNumber,
}) })
return comments.find((c) => c.body?.includes(COMMENT_TAG)) return comments.find((c) => c.body?.includes(COMMENT_TAG))
...@@ -310,7 +316,6 @@ async function updateComment( ...@@ -310,7 +316,6 @@ async function updateComment(
} }
async function createComment(comment: string): Promise<string> { async function createComment(comment: string): Promise<string> {
const isFork = pullRequest.head.repo.fork
if (isFork) { if (isFork) {
setFailed( setFailed(
'The action could not create a Github comment because it is initiated from a forked repo. View the action logs for a list of broken links.' 'The action could not create a Github comment because it is initiated from a forked repo. View the action logs for a list of broken links.'
...@@ -322,7 +327,7 @@ async function createComment(comment: string): Promise<string> { ...@@ -322,7 +327,7 @@ async function createComment(comment: string): Promise<string> {
const { data } = await octokit.rest.issues.createComment({ const { data } = await octokit.rest.issues.createComment({
owner, owner,
repo, repo,
issue_number: pullRequest.number, issue_number: prNumber,
body: comment, body: comment,
}) })
...@@ -346,7 +351,6 @@ async function updateCheckStatus( ...@@ -346,7 +351,6 @@ async function updateCheckStatus(
errorsExist: boolean, errorsExist: boolean,
commentUrl?: string commentUrl?: string
): Promise<void> { ): Promise<void> {
const isFork = pullRequest.head.repo.fork
const checkName = 'Docs Link Validation' const checkName = 'Docs Link Validation'
let summary, text let summary, text
......
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