Created
November 2, 2012 17:11
-
-
Save ekashida/4002815 to your computer and use it in GitHub Desktop.
trello progress poller for google drive spreadsheets
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
/*global UrlFetchApp:true,Utilities:true,SpreadsheetApp:true*/ | |
var KEY = <API_KEY>, | |
TOKEN = <TOKEN>, | |
BOARD = <BOARD_ID>, | |
BLACKLIST_RE = /stories/i; // list column names to ignore using regex alternation | |
function trelloFetch(request) { | |
'use strict'; | |
var url = 'https://api.trello.com/1/' + request + '?key=' + KEY + '&token=' + TOKEN, | |
res = UrlFetchApp.fetch(url), | |
json = res.getContentText(); | |
return Utilities.jsonParse(json); | |
} | |
function getBoardListCount() { | |
'use strict'; | |
var trelloLists = trelloFetch('boards/' + BOARD + '/lists'), | |
output = {}, | |
listNames = [], | |
listCounts = [], | |
trelloCards, | |
i; | |
for (i = 0; i < trelloLists.length; i += 1) { | |
if (!BLACKLIST_RE.test(trelloLists[i].name)) { | |
trelloCards = trelloFetch('lists/' + trelloLists[i].id + '/cards'); | |
listNames.push(trelloLists[i].name); | |
listCounts.push(trelloCards.length); | |
} | |
} | |
return { | |
names: listNames, | |
counts: listCounts | |
}; | |
} | |
function getValues() { | |
'use strict'; | |
var sheet = SpreadsheetApp.getActiveSheet(), | |
counterCell = sheet.getRange(1, 1), // counter stored at A1 | |
row = counterCell.getValue(), | |
data = getBoardListCount(); | |
// Add date to the first cell of row of card counts | |
data.counts.unshift(new Date()); | |
if (!row) { | |
sheet.getRange(1, 2, 1, data.names.length).setValues([data.names]); // fill first row with list names | |
sheet.getRange(2, 1, 1, data.counts.length).setValues([data.counts]); // fill second row with card counts | |
} else { | |
sheet.getRange(row, 1, 1, data.counts.length).setValues([data.counts]); | |
} | |
// If row is defined, increment; otherwise we initialize to the 3rd row. | |
counterCell.setValue(row ? row += 1 : 3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment