Skip to content

Commit

Permalink
fix: handle unbelievably pernicious edge case in ghbot
Browse files Browse the repository at this point in the history
  • Loading branch information
zkrising committed Apr 25, 2024
1 parent d9fe2a2 commit 5d1a446
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions github-bot/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)}`,
});
}
}
Expand Down

0 comments on commit 5d1a446

Please sign in to comment.