This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
44 lines (40 loc) · 1.72 KB
/
index.js
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
39
40
41
42
43
44
const Gh = require('@octokit/rest')
var gh = new Gh({
auth: `token ${process.env["TYPESCRIPT_BOT_WATCHDOG_TOKEN"] || ""}`
})
async function main() {
const activity = await recentActivity()
if (!activity) {
console.log("Couldn't find any recent activity for typescript-bot")
throw new Error()
}
const [anyRecent, botRecent] = activity
// 1. anyRecent - botRecent < 2 hours || present - botRecent < 2 hour
console.log()
console.log()
console.log("Time since typescript-bot's last activity: " + (new Date().valueOf() - botRecent.valueOf()) / 1000)
console.log("Time between most recent activity and typescript-bot's most recent activity: " + (anyRecent.valueOf() - botRecent.valueOf()) / 1000)
if ((new Date().valueOf() - botRecent.valueOf()) > 7200000 && (anyRecent.valueOf() - botRecent.valueOf()) > 7200000) {
console.log("typescript-bot hasn't responded or been active in over 2 hours (7200 seconds)")
throw new Error();
}
}
/** @returns {Promise<[Date, Date] | undefined>} */
async function recentActivity() {
const dtEvents = await gh.activity.listRepoEvents({owner: "DefinitelyTyped", repo: "DefinitelyTyped" })
let latestEvent
for (const event of dtEvents.data) {
latestEvent = new Date(event.created_at)
break
}
if (!latestEvent) {
throw new Error("couldn't get events for DefinitelyTyped repo")
}
const events = await gh.activity.listEventsForUser({ username: 'typescript-bot' })
for (const event of events.data) {
if (event.repo.name === 'DefinitelyTyped/DefinitelyTyped') {
return [latestEvent, new Date(event.created_at)]
}
}
}
main().catch(e => { console.log(e); process.exit(1) })