Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Issue Tracker Script Example
var SHEETNAME = "Sheet1";
var SPREADSHEETID = "YOUR_SPREED_SHEET_ID";
var message = "Sent: Thank you for sending this issue.";
function doGet(request)
{
return addIssue(request);
}
function doPost(request)
{
return ContentService.createTextOutput(JSON.stringify(addIssue(request)));
}
function createHeaders()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Freezes the first row
sheet.setFrozenRows(1);
var values = [ ["TimeStamp", "IGN", "Contact", "Issue", "Title", "Description","MPVersion","MCVersion", "ForgeVersion", "OS", "CrashLog", "Mod Cnt", "Java", "Cpu", "Gpu", "Mem", "Allocated", "ACTION"] ];
// Set the range of cells
var range = sheet.getRange("A1:R1");
sheet.getRange("F:F").setWrap(true);
sheet.getRange("E:E").setWrap(true);
sheet.getRange("R:R").setWrap(true);
sheet.getRange("1:1").setBackgroundRGB(211,211,211).setFontWeight("bold");;
sheet.getRange("A:R").setHorizontalAlignment("center").setVerticalAlignment("middle");
// Call the setValues method on range and pass in our values
range.setValues(values);
}
function addIssue(request)
{
var jsonString = request.postData.getDataAsString();
var jsonData = JSON.parse(jsonString);
var title = jsonData.title;
var desc = jsonData.desc;
var ign = jsonData.ign;
var forgeVersion = jsonData.forgeVersion;
var mcVersion = jsonData.mcVersion;
var mpVersion = jsonData.mpVersion;
var os = jsonData.os;
var java = jsonData.java;
var cpu = jsonData.cpu;
var gpu = jsonData.gpu;
var mem = jsonData.mem;
var allocated = jsonData.allocated;
var modsLoaded = jsonData.modsLoaded;
var issueType = jsonData.issueType;
var contactType = jsonData.contactType;
var email = jsonData.email;
Logger.log(jsonData.crashLog);
if(jsonData.crashLog != null)
{
var gistLink = createGist(jsonData.crashLogFile, jsonData.crashLog);
var crashLog = "=HYPERLINK(\""+ gistLink +"\", \"Link\")";
}
if(contactType.toLowerCase() == "email")
{
email = "=HYPERLINK(\"mailto:"+email+"\", \""+email+"\")";;
}
else email = contactType +":"+ email;
var timestamp = new Date();
var data = [[timestamp, ign, email, issueType, title, desc, mpVersion, mcVersion, forgeVersion, os, crashLog, modsLoaded, java, cpu, gpu, mem, allocated]];
var sheet = SpreadsheetApp.openById(SPREADSHEETID).getSheetByName(SHEETNAME);
var lastRow = sheet.getLastRow()+1;
var range = sheet.getRange(lastRow, 1, 1, 17);
range.setValues(data);
return setupJsonReturn(message, gistLink, timestamp)
}
function setupJsonReturn(inMessage, gistLink, timestamp)
{
var jsonReturn = {
"message" : inMessage,
"gistLink" : gistLink,
"timestamp" : timestamp.getTime()
}
return jsonReturn;
}
function createGist(filename, data)
{
var headers = {
"Accept":"application/vnd.github.v3+json",
"Content-Type":"application/json"
};
var payload = {"description": "CrashLog Added via MPUtils","public": true,"files": {filename: {"content": data}}};
var options = { "method":"POST",
"headers": headers,
"payload" : JSON.stringify(payload)
};
var response = UrlFetchApp.fetch("https://api.github.com/gists", options);
return JSON.parse(response.getContentText()).html_url;
}
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.