fix: handle unbelievably pernicious edge case in ghbot

This commit is contained in:
zkldi
2024-04-25 01:41:36 +01:00
parent d9fe2a2fc4
commit 5d1a44644f
+37 -12
View File
@@ -38,23 +38,48 @@ function ConvertGitHubURL(url: string) {
app.webhooks.on(
["pull_request.opened", "pull_request.edited"],
async ({ octokit, payload: body }) => {
const filesChanged = (await fetch(
`https://api.github.com/repos/zkldi/Tachi/pulls/${body.number}/files`
).then((r) => r.json())) as Array<{ filename: string }>;
try {
const filesChanged = (await fetch(
`https://api.github.com/repos/zkldi/Tachi/pulls/${body.number}/files`
).then((r) => r.json())) as Array<{ filename: string }>;
// if any file modified in this pr is a collection
if (filesChanged.some((k) => k.filename.startsWith("database-seeds/collections"))) {
// post a link to the diff viewer in the PR comments.
// if any file modified in this pr is a collection
if (filesChanged.some((k) => k.filename.startsWith("database-seeds/collections"))) {
// post a link to the diff viewer in the PR comments.
await octokit.request("POST /repos/{owner}/{repo}/issues/{issue_number}/comments", {
owner: body.repository.owner.login,
repo: body.repository.name,
issue_number: body.pull_request.number,
body: mkSeedDiffViewMsg(
body.pull_request.base.repo.url,
body.pull_request.base.sha,
body.pull_request.head.repo.url,
body.pull_request.head.sha
),
});
}
} catch (err) {
await octokit.request("POST /repos/{owner}/{repo}/issues/{issue_number}/comments", {
owner: body.repository.owner.login,
repo: body.repository.name,
issue_number: body.pull_request.number,
body: mkSeedDiffViewMsg(
body.pull_request.base.repo.url,
body.pull_request.base.sha,
body.pull_request.head.repo.url,
body.pull_request.head.sha
),
body: `I failed horribly figuring out whether this was a seeds diff or not. I'm sorry!
*****
Reason
\`\`\`
${err}
\`\`\`
*****
${mkSeedDiffViewMsg(
body.pull_request.base.repo.url,
body.pull_request.base.sha,
body.pull_request.head.repo.url,
body.pull_request.head.sha
)}`,
});
}
}