-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathcron.ts
38 lines (34 loc) · 1.14 KB
/
cron.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { getDateFromRepo } from "./helpers/github";
import { getDateFromSource } from "./helpers/puppeteer";
import { send } from "./helpers/telegram";
export async function compareDateValuesBetweenSourceAndRepo() {
const [
{ date: source, error: errorSource, png },
{ date: repo, error: errorRepo },
] = await Promise.all([
getDateFromSource().catch((error) => ({
date: undefined,
error,
png: undefined,
})),
getDateFromRepo().catch((error) => ({ date: undefined, error })),
]);
const sendMessage = (text: string) => send(text, { png });
if (errorSource || errorRepo) {
const summary: string[] = ["❌❌❌"];
summary.push("[getDateFromSource] " + (errorSource || `date=${source}`));
summary.push("[getDateFromRepo] " + (errorRepo || `date=${repo}`));
const errorMessage = summary.join("\n");
console.error(errorMessage);
await sendMessage(errorMessage);
return;
}
if (source === repo) {
const logMessage = `✅ ${repo}`;
console.log(logMessage);
return;
}
const warnMessage = `${source} ❌ ${repo}`;
console.warn(warnMessage);
await sendMessage(warnMessage);
}