Skip to content

Commit

Permalink
chore: update broken-link-checker to handle comment events
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed May 4, 2024
1 parent c2483b3 commit 016a118
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions .github/broken-link-checker/src/index.ts
Expand Up @@ -80,17 +80,24 @@ const postComment = async (outputMd: string) => {
const { context, getOctokit } = github
const octokit = getOctokit(process.env.GITHUB_TOKEN!)
const { owner, repo } = context.repo
const pullRequest = context.payload.pull_request
if (!pullRequest) {
console.log("Skipping since this is not a pull request")
process.exit(0)
}
const isFork = pullRequest.head.repo.fork
const prNumber = pullRequest.number
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."
)
console.log("CONTEXT", context.payload)
// const pullRequest = context.payload.pull_request
// if (!pullRequest) {
// console.log("Skipping since this is not a pull request")
// process.exit(0)
// }
// const isFork = pullRequest.head.repo.fork
// const prNumber = pullRequest.number
// 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."
// )
// return ""
// }
//
const prNumber = context.payload?.issue?.number
if (!prNumber) {
setFailed("Count not find PR Number")
return ""
}

Expand Down Expand Up @@ -157,9 +164,8 @@ const generateOutputMd = (output: Output): string => {

// @ts-expect-error
links.forEach((link: TODO) => {
outputMd += `| [${new URL(link.url.resolved).pathname}](${
link.url.resolved
}) | "${link.html?.text?.trim().replaceAll("\n", "")}" |
outputMd += `| [${new URL(link.url.resolved).pathname}](${link.url.resolved
}) | "${link.html?.text?.trim().replaceAll("\n", "")}" |
`
})
})
Expand Down

0 comments on commit 016a118

Please sign in to comment.