Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.