Last active
June 4, 2016 06:15
-
-
Save TheSkorm/4d095754e0565e51973c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This script can be run in AWS Lambda and simply just searches for all cards on a list and turns them into a checklist on a predefined card. | |
| // Any checklist items that are checked off will also remove the cards | |
| // The checklist can be deleted and will be created again with all the remaining cards. | |
| var Trello = require("trello"); | |
| var trello = new Trello("", ""); | |
| board = ''; | |
| list_check = ''; | |
| check_list_id = ""; | |
| check_list_card = ""; | |
| exports.handler = function(event, context) { | |
| checkCheckList() | |
| } | |
| cards = {} // name as key, value is id | |
| checklist_items = [] | |
| function checkCheckList(){ | |
| trello.getChecklistsOnCard(check_list_card, doneCheckListCheck); | |
| } | |
| function processCheckList(res, res2){ | |
| console.log(res) | |
| console.log(res2) | |
| trello.getCardsOnList(list_check, gotItems); | |
| } | |
| function doneCheckListCheck(res,res2){ | |
| if (res2.length == 0) { | |
| console.log("no checklist - creating") | |
| trello.addChecklistToCard(check_list_card, "Checklist", processCheckList); | |
| } else { | |
| console.log("using existing checklist") | |
| processCheckList() | |
| } | |
| } | |
| function gotCheckList(res, res2){ | |
| items = res2[0]["checkItems"] ; //TODO don't assume one checklist | |
| console.log(res2[0]) | |
| check_list_id = res2[0]["id"] | |
| for(i=0; i<items.length; i++){ | |
| checklist_items.push(items[i].name) | |
| if (items[i].state == 'complete') { | |
| console.log(items[i]) | |
| trello.deleteCard(cards[items[i].name]) | |
| delete cards[items[i].name] | |
| } | |
| } | |
| addNewCards(); | |
| } | |
| function gotItems(res, res2){ | |
| for(i=0; i<res2.length; i++){ | |
| if (res2[i].id != check_list_card){ | |
| cards[res2[i].name] = res2[i].id | |
| } | |
| } | |
| trello.getChecklistsOnCard(check_list_card, gotCheckList); | |
| } | |
| function addNewCards(){ | |
| Object.keys(cards).forEach(function(key) { | |
| if (checklist_items.indexOf(key) == -1) { | |
| trello.addItemToChecklist(check_list_id, key); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment