Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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