Skip to content

Instantly share code, notes, and snippets.

@khris
Created December 18, 2013 10:41
Show Gist options
  • Save khris/8020324 to your computer and use it in GitHub Desktop.
Save khris/8020324 to your computer and use it in GitHub Desktop.
Google Apps Script to add issues from spread sheet
function onOpen() {
var sheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'Add issues...', functionName: 'addIssues'}
];
sheet.addMenu('GitHub', menuItems);
}
function addIssues() {
var re = /^\[?.*\]?\s*(.*)$/;
var is_iOS = /ios/i;
var is_Android = /android/i;
var range = SpreadsheetApp.getActiveRange();
var datum = range.getValues();
var auth = '<Private Token>:x-oauth-basic';
var auth_token = 'Basic ' + Utilities.base64Encode(auth);
var headers = {
'Accept': 'application/vnd.github.v3',
'Authorization': auth_token,
};
var user = 'username';
var repo = 'reponame';
var url = 'https://api.github.com/repos/' + user + '/' + repo + '/issues';
for (i in datum) {
var row = datum[i];
var filtered = re.exec(row[0]);
var issue = filtered[0];
var labels = new Array();
if (row[0].search(is_iOS) != -1) {
labels.push('P-iOS');
}
if (row[0].search(is_Android) != -1) {
labels.push('P-Android');
}
var payload = {'title': issue, 'labels': labels};
var options = {
'method': 'post',
'headers': headers,
'payload': JSON.stringify(payload),
'muteHttpExceptions': true,
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment