/src/test/resources/examples/AutoCloseSubtasks.groovy
https://bitbucket.org/sorin/jira-plugin-intellij · Groovy · 35 lines · 27 code · 6 blank · 2 comment · 2 complexity · e3689a056a094eca4ab5a8d22ea53a02 MD5 · raw file
- package examples
-
- import com.atlassian.jira.ComponentManager
- import com.atlassian.jira.issue.comments.CommentManager
- import com.opensymphony.workflow.WorkflowContext
- import org.apache.log4j.Category
- import com.atlassian.jira.config.SubTaskManager
- import com.atlassian.jira.workflow.WorkflowTransitionUtil;
- import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
- import com.atlassian.jira.util.JiraUtils;
-
- log = Category.getInstance("com.onresolve.jira.groovy.AutoCloseChildIssues")
-
- String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
- WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
-
- SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
- Collection subTasks = issue.getSubTaskObjects()
- if (subTaskManager.subTasksEnabled && !subTasks.empty) {
- subTasks.each {
- log.debug ("issue.statusObject.name: " + issue.statusObject.name)
- workflowTransitionUtil.setIssue(it);
- workflowTransitionUtil.setUsername(currentUser);
- workflowTransitionUtil.setAction (5) // 5 == RESOLVE ISSUE
-
- // Add a comment so people have a clue why the child has been closed
- CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class);
- String comment = "*Resolving* as a result of the *Resolve* action being applied to the parent.";
- commentManager.create(it, currentUser, comment, true);
-
- // validate and transition issue
- workflowTransitionUtil.validate();
- workflowTransitionUtil.progress();
- }
- }