Sidehistorik
Tip |
---|
A hint - Dont let any "Post Function" call "Fire event *Issue Commented*" - this will make a loop, as the Listener call itself etc etc |
Kodeblok |
---|
// Class to Transist issues on Comments package com.netic.listener import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.link.IssueLink; import com.atlassian.jira.issue.comments.CommentManager import com.atlassian.jira.util.JiraUtils; import com.opensymphony.workflow.WorkflowContext; import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.event.issue.IssueEvent import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.workflow.WorkflowTransitionUtil; import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl; import com.atlassian.jira.util.JiraUtils; class ExampleListener extends AbstractIssueEventListener { ComponentManager componentManager = ComponentManager.getInstance(); def issueLinkManager = ComponentAccessor.getIssueLinkManager(); def authContext = componentManager.getJiraAuthenticationContext() // def currentuser = authContext.getUser().name WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class ); @Override void workflowEvent(IssueEvent event) { String issueid = event.issue.id String issuekey = event.issue.key String status = event.issue.getStatusObject().getName() String eventid = event.getEventTypeId() String issuetype = event.issue.issueTypeObject.name Integer transition = 0 String currentuser = "neticsupport" System.out.println("script=Listener.groovy IssueKey=" + issuekey + " action=StartScript") System.out.println("script=Listener.groovy IssueKey=" + issuekey + " currentUser=" + currentuser) System.out.println("script=Listener.groovy IssueKey=" + issuekey + " eventid=" + eventid) System.out.println("script=Listener.groovy IssueKey=" + issuekey + " issuetype=" + issuetype) System.out.println("script=Listener.groovy IssueKey=" + issuekey + " status=" + status) if (issuetype == "Task" || issuetype == "Service Request") { if (status == "Waiting for Customer") // Task And Service Request { if (issuetype == "Service Request") { transition = 831 // 831 = Reply from Customer System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 831") } if (issuetype == "Task") { transition = 841 // 841 = Reply from Customer System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 841") } } if (status == "Resolved" || status == "Closed") { transition = 3 // 3 = Reopen System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 3") } if (status == "Inactive") { transition = 761 // 761 = Reply from Customer System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 761") } if (status == "Frozen") { transition = 801 // 801 = Unfreeze System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 801") } } if (issuetype == "Incident") // Incident { if (status == "Awaiting External Response") { transition = 211 // 211 = Resume Investigation System.out.println("script=Listener.groovy IssueKey=" + issuekey + " setting transition to 211") } } if (transition != 0 ) { // Transist Issue workflowTransitionUtil.setIssue(event.issue); workflowTransitionUtil.setUsername(currentuser); workflowTransitionUtil.setAction (transition) // Validate and transition issue workflowTransitionUtil.validate(); workflowTransitionUtil.progress(); status = event.issue.getStatusObject().getName() System.out.println("script=Listener.groovy IssueKey=" + issuekey + " Issue " + issueid + " transited to new status: " + status) } System.out.println("script=Listener.groovy IssueKey=" + issuekey + " action=EndScript") } } |
...