Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created June 3, 2014 19:39
Show Gist options
  • Save jechlin/b508f0fcd6f163eb55df to your computer and use it in GitHub Desktop.
Save jechlin/b508f0fcd6f163eb55df to your computer and use it in GitHub Desktop.
package examples
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.scriptrunner.canned.jira.utils.WorkflowUtils
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.WorkflowDescriptor
/**
* Transition all subtasks through the same action as the parent
*
* Doesn't handle fields required through screens or validators
*
* Can be set up as a listener or post-function
*/
def workflowManager = ComponentAccessor.getWorkflowManager()
def user = ComponentAccessor.getJiraAuthenticationContext()?.getLoggedInUser()
Issue issue = issue
if (issue.isSubTask()) {
return
}
// get workflow action
def actionId = transientVars["actionId"] as Integer
def descriptor = transientVars.get("descriptor") as WorkflowDescriptor
def parentActionName = descriptor.getAction(actionId).getName()
issue.subTaskObjects.each {subtask ->
def workflow = workflowManager.getWorkflow(subtask)
def action = workflow.getLinkedStep(subtask.statusObject).getActions().find {it.name == parentActionName} as ActionDescriptor
if (action) {
WorkflowUtils.actionIssue(null, subtask as MutableIssue, action.id, user)
}
else {
log.debug("No action with '$parentActionName' found")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment