Skip to content

Commit 3e00e8b

Browse files
committed
feat: add script to set up webhooks
1 parent ee7027c commit 3e00e8b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/set-up-webhooks.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { trelloApi } from './trello/api'
2+
import { config } from 'dotenv'
3+
4+
config()
5+
6+
const apiKey = process.env.API_KEY!
7+
const apiToken = process.env.API_TOKEN!
8+
const websiteContentList = process.env.WEBSITE_CONTENT_LIST!
9+
const netlifyWebhook = process.env.NETLIFY_WEBHOOK!
10+
11+
const api = trelloApi({ apiKey, apiToken })
12+
13+
Promise.all([
14+
// Delete existing webhooks
15+
api.tokens
16+
.token({ token: apiToken })
17+
.webhooks()
18+
.then(webhooks =>
19+
Promise.all(webhooks.map(({ id }) => api.webhook({ id }).delete())),
20+
),
21+
// Fetch cards
22+
api.lists.cards({
23+
list: websiteContentList,
24+
}),
25+
])
26+
.then(([_, cards]) =>
27+
Promise.all(
28+
cards.map(({ id, name }) =>
29+
api.webhooks.create({
30+
active: true,
31+
callbackURL: netlifyWebhook,
32+
description: `Notify Netlify if ${name} card has changed`,
33+
idModel: id,
34+
}),
35+
),
36+
),
37+
)
38+
.then(() =>
39+
api.tokens
40+
.token({ token: apiToken })
41+
.webhooks()
42+
.then(webhooks => {
43+
console.log(webhooks)
44+
}),
45+
)
46+
.catch(error => {
47+
console.error(error)
48+
process.exit(1)
49+
})

0 commit comments

Comments
 (0)