Skip to content

Commit 5e7b15e

Browse files
committed
build(update-known-events): initial version
1 parent a7b7219 commit 5e7b15e

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

scripts/update-known-events.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const axios = require('axios')
2+
const cheerio = require('cheerio')
3+
const { writeFileSync } = require('fs')
4+
5+
updateKnownEventTypes()
6+
7+
async function updateKnownEventTypes () {
8+
const { data } = await axios.get('https://developer.github.com/v3/activity/events/types/')
9+
const $ = cheerio.load(data)
10+
11+
const events = $('h3')
12+
.filter((index, el) => $(el).text().trim() === 'Webhook event name')
13+
.map((index, el) => {
14+
const name = $(el).nextUntil('h2, h3').last().text().trim()
15+
const $table = $(el).prev()
16+
17+
if (!$table.is('table')) {
18+
return {
19+
name,
20+
actions: []
21+
}
22+
}
23+
24+
const [keyEl,, descriptionEl] = $table.find('tbody tr:first-child td').get()
25+
26+
if ($(keyEl).text().trim() !== 'action') {
27+
return {
28+
name,
29+
actions: []
30+
}
31+
}
32+
33+
const actions = $(descriptionEl)
34+
.find('code')
35+
.map((index, el) => {
36+
return $(el).text().trim()
37+
})
38+
.get()
39+
40+
return {
41+
name,
42+
actions
43+
}
44+
})
45+
.get()
46+
47+
const newWebhookNames = events.reduce((list, event) => {
48+
list.push(event.name, ...event.actions.map(action => `${event.name}.${action}`))
49+
return list
50+
}, ['*', 'error'])
51+
52+
// the documentation at https://developer.github.com/v3/activity/events/types/#labelevent
53+
// does not include all actions, or the actions are not formatted correctly.
54+
// So for the time being we merge into the current webhook names to prevent
55+
// events or actions from being removed
56+
const currentWebhookNames = require('../lib/webhook-names')
57+
const webhookNames = new Set(newWebhookNames.concat(currentWebhookNames).sort())
58+
59+
writeFileSync('lib/webhook-names.json', JSON.stringify([...webhookNames], null, 2) + '\n')
60+
}

0 commit comments

Comments
 (0)