Skip to content

Instantly share code, notes, and snippets.

@paulrouget
Created February 7, 2012 10: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 paulrouget/1758942 to your computer and use it in GitHub Desktop.
Save paulrouget/1758942 to your computer and use it in GitHub Desktop.
Prettify Bugzilla Activity Report
var rows = document.querySelectorAll("#report > tbody > tr:not(#report-header)")
var bugs = {};
var currentBug = null;
var currentDate = null;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
// new bug?
var a = row.querySelector('td[valign="top"] > a');
var offset = 0;
if (a) {
// Yes, new bug
currentBug = a.textContent;
bugs["_" + currentBug] = [];
offset = 2;
currentDate = row.querySelector('td[valign="top"]:first-child').textContent.trim();
}
var bug = bugs["_" + currentBug];
var tds = row.querySelectorAll("td");
function trim(str) {
str = str.trim();
str = str.replace(/\n/g, "");
str = str.replace(/[\s]+/g, " ");
return str;
}
var action = {};
action.date = currentDate;
action.what = trim(tds[offset].textContent);
action.removed = trim(tds[offset + 1].textContent);
action.added = trim(tds[offset + 2].textContent);
bug.push(action);
};
// Pretty print bug:
var txt = "";
for (var id in bugs) {
var bug = bugs[id];
txt += id.substr(1, 6) + ": ";
bug = bug.sort(function(a1, a2) {
return a1.date < a2.date;
});
bug.forEach(function(a) {
txt += a.what + ": " + (a.removed?a.removed:"null");
txt += "⇢ " + (a.added?a.added:"null") + "\n\ \ \ \ \ \ \ \ ";
});
txt += "\n";
}
var t = document.createElement("textarea");
t.value = txt;
t.setAttribute("style", "width: 100%;height:500px");
document.querySelector("#activity_form").appendChild(t);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment