Skip to content

Instantly share code, notes, and snippets.

@dveditz dveditz/bug-age.txt
Created Aug 28, 2019

Embed
What would you like to do?
"Bug age" bookmarklet for bugzilla bug lists
Save the javascript url below as a bookmarklet and run it on a bugzilla query list of bugs to get basic age stats for that buglist. The answers will be shown in an alert as well as appended to the bottom of the document. It will look something like:
total: 7
median age: 13 days
oldest: 235 days
median last touched: 3 days
least active untouched for 189 days
Caveats:
1. This works at bugzilla.mozilla.org. I have not tried other bugzillas
2. The columnlist doesn't seem to work on named (saved) queries. On those you'll get a "wrong columns!" alert unless you've customized your default columns to show the open and changeddate columns first.
javascript:function%20rcmp(a,b){return%20b-a;}function%20age(date){var%20t=date.match(/(....)-(..)-(..)%20(..)/);return%20Math.round((Date.now()-(new%20Date(t[1],t[2]-1,t[3],t[4])))/86400000);}function%20median(a){var%20mid=Math.floor(a.length/2);return(a.length%2)?a[mid]:Math.floor((a[mid]+a[mid-1])/2);}function%20agecalc(buglist){var%20bugs=buglist.split('\n');if(!bugs[0].match('^bug_id,\"opendate\",\"changeddate')){alert('wrong%20columns!%20'+bugs[0]);throw%20'oops';}bugs.shift();bugs.forEach(function(v,i,a){a[i]=v.split(',')});var%20dopen=bugs.map(function(v,i,a){return%20age(a[i][1])});var%20dmod=bugs.map(function(v,i,a){return%20age(a[i][2])});dopen.sort(rcmp);dmod.sort(rcmp);return'total:%20'+bugs.length+'\nmedian%20age:%20'+median(dopen)+'%20days\noldest:%20'+dopen[0]+'%20days\nmedian%20last%20touched:%20'+median(dmod)+'%20days\nleast%20active%20untouched%20for%20'+dmod[0]+'%20days';}function%20getlist(){var%20url=document.location+'&columnlist=opendate,changeddate&ctype=csv';var%20req=new%20XMLHttpRequest();req.open('GET',url,false);req.send();return%20req.responseText;}var%20bugage=document.createElement('pre');bugage.textContent=agecalc(getlist());document.body.firstElementChild.lastElementChild.appendChild(bugage);alert(bugage.textContent);
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.