mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-01 03:18:06 +03:00
fix: handle unbelievably pernicious edge case in ghbot
This commit is contained in:
+37
-12
@@ -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
|
||||
)}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user