Can't figure out how to get attachment sizing trends out of JIRA.
Example:
Unzipped
Zipped
Total Attachments by Month
Month
Files
Bytes
2014-01
2,264
2,117,700,771
575
1,608,367,762
2,839
3,726,068,533
2014-02
2,053
1,713,796,369
372
1,388,456,805
2,425
3,102,253,174
Here's a Groovy Script Runner sample code that will get you a nice HTML table. You can put this script into a scripted field or anywhere else that you can execute groovy code.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.AttachmentManager import com.atlassian.jira.issue.attachment.Attachment; import com.atlassian.jira.issue.attachment.AttachmentConstants import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import java.text.SimpleDateFormat; import org.joda.time.DateTime List<Attachment> attachments = ComponentAccessor.getOfBizDelegator().findAll(AttachmentConstants.ATTACHMENT_ENTITY_NAME).collect({ ComponentAccessor.getAttachmentManager().getAttachment(it.getLong("id")) }) SimpleDateFormat monthFormat = new SimpleDateFormat("Y-MM"); Multimap<String, Attachment> multimap = ArrayListMultimap.create(); attachments.each({ multimap.put(monthFormat.format(it.created), it) }) def zipmimes = ["application/zip"] def lines = multimap.keySet().collect({ key -> def atts = multimap.get(key) def tfiles = atts.size() def tbytes = String.format("%,8d%n",atts.sum{it.filesize }?:0) // def zips = atts.findAll({it.zip || zipmimes.contains(it.mimetype)}) def zfiles = zips.size() def zbytes = String.format("%,8d%n",zips.sum{it.filesize}?:0) // def uzips = atts.findAll({!it.zip && !zipmimes.contains(it.mimetype)}) def uzfiles = uzips.size() def uzbytes = String.format("%,8d%n", uzips.sum{it.filesize}?:0) "<tr><td>$key</td><td>$uzfiles</td><td>$uzbytes</td><td>$zfiles</td><td>$zbytes</td><td>$tfiles</td><td>$tbytes</td>" }) $/ <table class="aui"> <thead><tr><th id="month">Month</th><th id="name" colspan="2">Unzipped</th><th id="type" colspan="2">Zipped</th> <th id="order" colspan="2">Total Attachments by Month</th></tr></thead> <tbody> <tr><td>Month</td><td>Files</td><td>Bytes</td><td>Files</td><td>Bytes</td><td>Files</td><td>Bytes</td>${lines.join()} </tbody> </table> /$
Here's a sample table produced by this script:
Well, figured out the first part of my idiocy. which was expecting it to run NOT in admin>script fields. I do have a follow-up, though. We have a couple of exception errors on it.
Mostly property errors in static type checking
image2016-5-26 10:25:26.png
You can ignore static type checks or modify the code and add types to the variables. Is it working now ?
No; selecting Preview only swirls into oblivion with timeout error. If I bypass preview and simply add the script to the field, then the executions fail.
It looks like you're new here. Sign in or register to get started.