Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/scripts/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
GITHUB_TOKEN=
POSTGRES_URL=
POSTGRES_URL=
TELEGRAM_BOT_TOKEN=
TELEGRAM_CHAT_ID=
7 changes: 5 additions & 2 deletions packages/scripts/src/check-repo-online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import dotenv from "dotenv";
import { pool, delay, setupGracefulShutdown, githubHeaders } from "./common";
import { notifyTelegramOnError } from "./telegram-error-notify";

dotenv.config();

Expand Down Expand Up @@ -237,9 +238,11 @@ async function main() {
await pool.end();
}

main().catch(err => {
main().catch((err) => {
console.error("Unhandled error:", err);
process.exit(1);
notifyTelegramOnError("check-repo-online", err).finally(() => {
process.exit(1);
});
});


5 changes: 4 additions & 1 deletion packages/scripts/src/fetch-dependents-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
type RepositoryData,
type GitHubRepoResponse,
} from "./common";
import { notifyTelegramOnError } from "./telegram-error-notify";

dotenv.config();

Expand Down Expand Up @@ -167,5 +168,7 @@ async function main() {

main().catch((err) => {
console.error("Unhandled error:", err);
process.exit(1);
notifyTelegramOnError("fetch-dependents-api", err).finally(() => {
process.exit(1);
});
});
8 changes: 7 additions & 1 deletion packages/scripts/src/scrape-dependents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
setupGracefulShutdown,
type RepositoryData,
} from "./common";
import { notifyTelegramOnError } from "./telegram-error-notify";

const BASE_URL =
"https://github.com/scaffold-eth/burner-connector/network/dependents?dependent_type=REPOSITORY";
Expand Down Expand Up @@ -157,4 +158,9 @@ const BASE_URL =

await pool.end();
await browser.close();
})();
})().catch((err) => {
console.error("Unhandled error:", err);
notifyTelegramOnError("scrape-dependents", err).finally(() => {
process.exit(1);
});
});
5 changes: 4 additions & 1 deletion packages/scripts/src/search-by-filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
setupGracefulShutdown,
type RepositoryData,
} from "./common";
import { notifyTelegramOnError } from "./telegram-error-notify";

dotenv.config();

Expand Down Expand Up @@ -149,5 +150,7 @@ async function main() {

main().catch((err) => {
console.error("Unhandled error:", err);
process.exit(1);
notifyTelegramOnError("search-by-filename", err).finally(() => {
process.exit(1);
});
});
5 changes: 4 additions & 1 deletion packages/scripts/src/search-initial-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
setupGracefulShutdown,
type RepositoryData,
} from "./common";
import { notifyTelegramOnError } from "./telegram-error-notify";

dotenv.config();

Expand Down Expand Up @@ -168,6 +169,8 @@ async function main() {

main().catch((err) => {
console.error("Unhandled error:", err);
process.exit(1);
notifyTelegramOnError("search-initial-commits", err).finally(() => {
process.exit(1);
});
});

56 changes: 56 additions & 0 deletions packages/scripts/src/telegram-error-notify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const TELEGRAM_BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
const TELEGRAM_CHAT_ID = process.env.TELEGRAM_CHAT_ID;

export async function notifyTelegramOnError(
scriptName: string,
err: unknown
): Promise<void> {
if (!TELEGRAM_BOT_TOKEN || !TELEGRAM_CHAT_ID) {
console.warn(
"Telegram notification skipped: TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID not set."
);
return;
}

const errorText =
err instanceof Error
? `${err.name}: ${err.message}\n${err.stack || ""}`
: JSON.stringify(err, null, 2);

const text = [`[${scriptName}] Unhandled error occurred:`, "", errorText].join(
"\n"
);

try {
const url = `https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage`;
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
chat_id: TELEGRAM_CHAT_ID,
text,
}),
});

if (!res.ok) {
const errorText = await res.text();
console.error(
`Failed to send Telegram error notification: ${res.status} ${res.statusText}`,
errorText
);
return;
}

const result = await res.json();
if (!result.ok) {
console.error(
`Telegram API error: ${result.description || "Unknown error"}`,
result
);
}
} catch (notifyErr) {
console.error("Failed to send Telegram error notification:", notifyErr);
}
}