Skip to content

Instantly share code, notes, and snippets.

@jechlin
Last active August 29, 2015 13:59
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 jechlin/10928320 to your computer and use it in GitHub Desktop.
Save jechlin/10928320 to your computer and use it in GitHub Desktop.
package examples.old
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.Issue
import com.atlassian.core.util.DateUtils
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
def inProgressName = "Open"
def rt = [0]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item ->
item.toString == inProgressName
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == inProgressName) {
rt << -timeDiff
}
if (item.toString == inProgressName){
rt << timeDiff
}
}
if (! changeItems) {
rt << (System.currentTimeMillis() - issue.getCreated().getTime())
}
// doesn't show anything if less than 60 seconds
DateUtils.getDurationString(Math.round(rt.sum() / 1000)) ?: "0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment