Skip to content

Commit cdfbac3

Browse files
committed
Add some ScriptRunner snippets that can be used in transitions.
1 parent e576534 commit cdfbac3

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Stories with open blocking issues should not be set to Done.
3+
The button disappears from the issue view.
4+
5+
This is meant to be added as a Condition on a transition.
6+
*/
7+
8+
import com.atlassian.jira.issue.*;
9+
import com.atlassian.jira.component.ComponentAccessor;
10+
import com.atlassian.jira.issue.link.*;
11+
import java.util.List
12+
13+
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
14+
def issueManager = ComponentAccessor.getIssueManager()
15+
16+
// issue is a special variable of the context of the transition
17+
def issue = issue
18+
19+
// https://scriptrunner.adaptavist.com/latest/jira/custom-workflow-functions.html, see under Conditions
20+
passesCondition = true
21+
22+
if(issue.getIssueType().getName() == "Story"){
23+
List links = issueLinkManager.getInwardLinks(issue.id)
24+
for(IssueLink issueLink : links){
25+
if(issueLink.issueLinkType.name == "Is blocked by"){
26+
def status = issueLink.destinationObject.getStatus().getName()
27+
if(!["Rejected", "Done"].contains(status)){
28+
passesCondition = false
29+
break;
30+
}
31+
}
32+
}
33+
}
34+
// functional programming style, no need for return
35+
passesCondition
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
This small snippet can be used ass a post-function in a workflow to allow
3+
automatically assigning the new sub-task to the story assignee, unless
4+
one was provided during creation.
5+
*/
6+
7+
import com.atlassian.jira.component.ComponentAccessor;
8+
import com.atlassian.jira.issue.*;
9+
10+
def customFieldManager = ComponentAccessor.getCustomFieldManager()
11+
def optionsManager = ComponentAccessor.getOptionsManager()
12+
13+
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
14+
15+
if(issue.getIssueType().isSubTask()) {
16+
def parent = issue.getParentObject()
17+
if (parent != null && issue.getAssignee() == null){
18+
issue.setAssignee(parent.getAssignee())
19+
}
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
Set the story status to In Progress when a Sub-task is set to In progress.
3+
*/
4+
5+
import com.atlassian.jira.component.ComponentAccessor
6+
import com.atlassian.jira.config.SubTaskManager;
7+
import com.atlassian.jira.issue.Issue;
8+
import com.atlassian.jira.issue.MutableIssue;
9+
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
10+
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
11+
import com.atlassian.jira.util.JiraUtils;
12+
import com.opensymphony.workflow.WorkflowContext;
13+
14+
Issue issue = issue
15+
16+
def issueService = ComponentAccessor.getIssueService()
17+
def currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
18+
19+
if(issue.isSubTask()) {
20+
// Need to use a mutable object to have read/write to parent, i.e., story
21+
MutableIssue parent = issue.getParentObject() as MutableIssue
22+
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)
23+
24+
String originalParentStatus = parent.getStatus().getSimpleStatus().getName()
25+
def isDevBacklogStatus = originalParentStatus in ['To Do', 'Clarification']
26+
27+
if (isDevBacklogStatus) {
28+
workflowTransitionUtil.setIssue(parent)
29+
// 21 is the id of "In Progress", see Text of the Workflow
30+
// The state name can't be used directly
31+
workflowTransitionUtil.setAction(21)
32+
if (workflowTransitionUtil.validate()) {
33+
workflowTransitionUtil.progress()
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)