File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments