Skip to content

Instantly share code, notes, and snippets.

@y-ogi
Created August 18, 2011 15:07
Show Gist options
  • Save y-ogi/1154254 to your computer and use it in GitHub Desktop.
Save y-ogi/1154254 to your computer and use it in GitHub Desktop.
Import from GitHub's Issues to Spreadsheet
var HEADERS = [
'ID',
'By',
'Title',
'Content',
'Created At',
'Updated At',
'Status'
];
var VALUES = [
'number',
'user',
'title',
'body',
'created_at',
'updated_at',
'state'
];
function isNumber(n) {
return !isNaN(n - 0);
}
function getDataFromGitHub(user, pass, repo) {
var options = {
'headers': {'Authorization': 'Basic ' + Utilities.base64Encode(user + ':' + pass)},
'contentType': 'application/json; charset=utf-8',
'method': 'get'
};
var resp = UrlFetchApp.fetch('http://github.com/api/v2/json/issues/list' + repo + '/open', options);
if(resp.getResponseCode() == 200) {
var j = JSON.parse(resp.getContentText());
return j;
}
}
function plotIssues(issues) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// plot header
for(var i = 0; i < HEADERS.length; i++) {
var cell = sheet.getRange(1, i + 1);
cell.setValue(HEADERS[i]);
cell.setHorizontalAlignment('center');
}
// plot rows
for(var i = 0; i < issues.length; i++) {
for(var j = 0; j < VALUES.length; j++) {
var cell = sheet.getRange(i + 2, j + 1);
var value = issues[i][VALUES[j]];
// setting align
cell.setVerticalAlignment('center');
if(isNumber(value)) {
cell.setHorizontalAlignment('center');
} else {
cell.setHorizontalAlignment('left');
}
// set value
cell.setValue(value);
}
}
}
function importFromGitHub() {
var user = Browser.inputBox('user');
var pass = Browser.inputBox('password');
var repo = Browser.inputBox('repo');
plotIssues(getDataFromGitHub(user, pass, repo).issues);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment