Skip to content

Instantly share code, notes, and snippets.

@clarkbw
Created February 18, 2014 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkbw/9081478 to your computer and use it in GitHub Desktop.
Save clarkbw/9081478 to your computer and use it in GitHub Desktop.
trying to capture bug references e.g. 'bug 314159' in a Google spreadsheet and convert it to a link
function onEdit(e) {
// https://code.google.com/p/google-apps-script-issues/issues/detail?id=2521
// var e = { range: SpreadsheetApp.getActiveRange(), value : "bug 972929" };
function fetchBug(bugNumber) {
var url = "https://api-dev.bugzilla.mozilla.org/latest/bug/" + bugNumber;
var parameters = {};
var response = UrlFetchApp.fetch(url, parameters);
var json = response.getContentText();
var data = JSON.parse(json);
return data;
}
var bugRegex = /bug\s(\d+)/;
// The presence of e.value indicates this is a single cell edit
if (e && e.value && bugRegex.test(e.value)) {
var bug = e.value.match(bugRegex)[1];
var data = fetchBug(bug);
var link = "https://bugzilla.mozilla.org/show_bug.cgi?id=" + data["id"];
var title = "Bug " + data["id"] + " " + "(" + data["summary"] + ")";
if (data['assigned_to'] && data['assigned_to']['name'] && data['assigned_to']['name'] != 'nobody') {
e.range.setComment("Assigned To: " + data['assigned_to']['real_name']);
}
e.range.setFormula("=HYPERLINK(\"" + link + "\", \"" + title + "\")");
} else {
Logger.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment