Created
February 23, 2012 17:06
-
-
Save luebken/1893771 to your computer and use it in GitHub Desktop.
grab points from trello and puts them into a google spreadsheet
This file contains 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
// trello variables | |
var api_key = "<your_api_key>"; | |
var api_token = "<your_api_token>"; | |
var board_id = "<your_board_id>"; | |
var url = "https://api.trello.com/1/"; | |
// google variables | |
var spreadsheet = "<your_spreadsheet_id>"; | |
var key_and_token = "key="+api_key+"&token="+api_token; | |
var pointsPerListAndLabel = function(lists) { | |
var pointsPerList = {}; | |
//configure for a different the column order | |
pointsPerList.ReleasedChore = 0; | |
pointsPerList.ReleasedFeature = 0; | |
pointsPerList.TotalChore = 0; | |
pointsPerList.TotalFeature = 0; | |
pointsPerList.ReleasedBug = 0; | |
pointsPerList.TotalBug = 0; | |
for (var i=0; i < lists.length; i++) { // | |
var list = lists[i]; | |
if(list.closed) continue; //ignore closed / archived lists | |
for (var j=0; j < list.cards.length; j++) { | |
var card = list.cards[j]; | |
var response = UrlFetchApp.fetch(url + "cards/" + card.id + "/?" + key_and_token); | |
var full_card = JSON.parse(response.getContentText()); | |
if(!full_card) continue; | |
var label = full_card.labels[0].name; | |
var n = card.name.match(/\((\d+)\)/); | |
if(n && list.name != "Backlog") { //ignore Backlog and Cards with no points | |
var points = parseInt(n[1]); | |
pointsPerList["Total"+label] += points; | |
if(list.name == "Released") { | |
pointsPerList["Released"+label] += points; | |
} | |
} | |
} | |
} | |
return pointsPerList; | |
} | |
//configure the data row inserted into the spreadsheet | |
var data_row = function(pointsPerListAndLabel) { | |
var result = []; | |
for(list_name in pointsPerListAndLabel) { | |
result.push(pointsPerListAndLabel[list_name]); | |
} | |
return result; | |
} | |
//called by google docs apps | |
function main() { | |
var response = UrlFetchApp.fetch(url + "boards/" + board_id + "/lists/all/?" + key_and_token); | |
var lists = JSON.parse((response.getContentText())); | |
var points = pointsPerListAndLabel(lists); | |
Logger.log(points); | |
var ss = SpreadsheetApp.openById(spreadsheet).getActiveSheet(); | |
ss.appendRow(data_row(points)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment