Skip to content

Commit 016a118

Browse files
committed
chore: update broken-link-checker to handle comment events
1 parent c2483b3 commit 016a118

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

.github/broken-link-checker/src/index.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,24 @@ const postComment = async (outputMd: string) => {
8080
const { context, getOctokit } = github
8181
const octokit = getOctokit(process.env.GITHUB_TOKEN!)
8282
const { owner, repo } = context.repo
83-
const pullRequest = context.payload.pull_request
84-
if (!pullRequest) {
85-
console.log("Skipping since this is not a pull request")
86-
process.exit(0)
87-
}
88-
const isFork = pullRequest.head.repo.fork
89-
const prNumber = pullRequest.number
90-
if (isFork) {
91-
setFailed(
92-
"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."
93-
)
83+
console.log("CONTEXT", context.payload)
84+
// const pullRequest = context.payload.pull_request
85+
// if (!pullRequest) {
86+
// console.log("Skipping since this is not a pull request")
87+
// process.exit(0)
88+
// }
89+
// const isFork = pullRequest.head.repo.fork
90+
// const prNumber = pullRequest.number
91+
// if (isFork) {
92+
// setFailed(
93+
// "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."
94+
// )
95+
// return ""
96+
// }
97+
//
98+
const prNumber = context.payload?.issue?.number
99+
if (!prNumber) {
100+
setFailed("Count not find PR Number")
94101
return ""
95102
}
96103

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

158165
// @ts-expect-error
159166
links.forEach((link: TODO) => {
160-
outputMd += `| [${new URL(link.url.resolved).pathname}](${
161-
link.url.resolved
162-
}) | "${link.html?.text?.trim().replaceAll("\n", "")}" |
167+
outputMd += `| [${new URL(link.url.resolved).pathname}](${link.url.resolved
168+
}) | "${link.html?.text?.trim().replaceAll("\n", "")}" |
163169
`
164170
})
165171
})

0 commit comments

Comments
 (0)