Created
September 20, 2015 11:06
-
-
Save jechlin/408b4ad91d0bbb3017c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples | |
import com.atlassian.jira.ComponentManager | |
import org.apache.log4j.Category | |
import java.text.SimpleDateFormat | |
// Logger | |
def Category log = Category.getInstance("com.onresolve.jira.groovy.zzz_Get_History_For_Issue") | |
def changeLoop = 0 | |
def historyLoop = 0 | |
def historyItemLoop = 0 | |
// Set the logging level to INFO | |
log.setLevel(org.apache.log4j.Level.DEBUG) | |
log.debug "checking $issue ${issue.getClass()} ${issue.getResolution()}" | |
if(issue.resolutionDate){ | |
log.info "issue is completed $issue.resolution" | |
//This script is used by a Scripted Field that is used by XPorter in the PDFS to display an issues History | |
ComponentManager componentManager = ComponentManager.getInstance() | |
log.info "Starting zzz Get History for Issue Script for $issue.key" | |
def changeHistoryManager = componentManager.getChangeHistoryManager() | |
def SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm") | |
def changehistoryItems = changeHistoryManager.getAllChangeItems(issue); | |
def StringBuffer html = new StringBuffer() | |
html.append "Issue $issue.key ChangeLog Items\n" | |
changehistoryItems.each{ historyItem -> | |
def creationDate = formatter.format((Date)historyItem.created) | |
historyItemLoop++ | |
log.info "## in change history item loop $historyItemLoop time(s)##" | |
if (historyItem.field =="status") { | |
def from = historyItem.froms.toString() | |
def to = historyItem.tos.toString() | |
html.append "\n$creationDate - Status Changed From: $from To: $to by $historyItem.user." | |
} else if (historyItem.field!="status") { | |
def changehistories = changeHistoryManager.getChangeHistories(issue) | |
changehistories.each() { changeHistory -> | |
def changeitems = changeHistory.getChangeItemBeans() | |
historyLoop++ | |
log.info "## in change history loop $historyLoop time(s)##" | |
changeitems.each(){ changeItem -> | |
changeLoop++ | |
log.info "## in change items loop $changeLoop time(s)##" | |
if(changeItem.field == historyItem.field && changeItem.created == historyItem.created){ | |
def fromValue = changeItem.fromString | |
def toValue = changeItem.toString | |
if (fromValue && fromValue.contains("<br>")){ | |
fromValue = fromValue.replaceAll("<br>","\n").replaceAll("<div>","").replaceAll("</div>",""); | |
} | |
if (toValue && toValue.contains("<br>")){ | |
toValue = toValue.replaceAll("<br>","\n").replaceAll("<div>","").replaceAll("</div>",""); | |
} | |
html.append "\n$creationDate - $historyItem.user changed $historyItem.field FROM $fromValue TO $toValue." | |
} | |
} | |
} | |
html.append "\n" | |
} | |
} | |
log.info "Ending zzz Get History for Issue Script for $issue.key" | |
html.toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment