Skip to content

Commit

Permalink
chore(ci): fix validate-docs-links for non-PR (#53129)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
styfle committed Jul 24, 2023
1 parent 8dede2a commit 48375e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/actions/validate-docs-links/lib/index.js

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions .github/actions/validate-docs-links/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ const COMMENT_TAG = '<!-- LINK_CHECKER_COMMENT -->'
const { context, getOctokit } = github
const octokit = getOctokit(process.env.GITHUB_TOKEN!)
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 isFork = pullRequest.head.repo.fork
const prNumber = pullRequest.number

const slugger = new GithubSlugger()

Expand Down Expand Up @@ -280,7 +286,7 @@ async function findBotComment(): Promise<Comment | undefined> {
const { data: comments } = await octokit.rest.issues.listComments({
owner,
repo,
issue_number: pullRequest.number,
issue_number: prNumber,
})

return comments.find((c) => c.body?.includes(COMMENT_TAG))
Expand Down Expand Up @@ -310,7 +316,6 @@ async function updateComment(
}

async function createComment(comment: string): Promise<string> {
const isFork = pullRequest.head.repo.fork
if (isFork) {
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.'
Expand All @@ -322,7 +327,7 @@ async function createComment(comment: string): Promise<string> {
const { data } = await octokit.rest.issues.createComment({
owner,
repo,
issue_number: pullRequest.number,
issue_number: prNumber,
body: comment,
})

Expand All @@ -346,7 +351,6 @@ async function updateCheckStatus(
errorsExist: boolean,
commentUrl?: string
): Promise<void> {
const isFork = pullRequest.head.repo.fork
const checkName = 'Docs Link Validation'

let summary, text
Expand Down

0 comments on commit 48375e4

Please sign in to comment.