Skip to content

Instantly share code, notes, and snippets.

@two7sclash-zz
Created September 19, 2016 15:04
Show Gist options
  • Save two7sclash-zz/9ed3f2dd1eb06df8f03052ca4f343eb1 to your computer and use it in GitHub Desktop.
Save two7sclash-zz/9ed3f2dd1eb06df8f03052ca4f343eb1 to your computer and use it in GitHub Desktop.
JIRA: Grooy Script Listener - update parent ticket to date of furthermost out subtask
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
/**
* Set max DueDate of all subtasks to parent issue
*/
//Get parent issue
Issue issue = (Issue) event.issue;
//Check, that it is a subtask type issue
if(!issue.isSubTask())
return
MutableIssue parentIssue = issue.getParentObject();
Set issueLabels = parentIssue.getLabels();
boolean containsLabel = false;
for (String label : issueLabels) {
if (label.contains("complex")){
containsLabel = true;
}}
if(!containsLabel)
return
//Get max due date of all subtasks
Timestamp maxSubtakDueDate = parentIssue.getDueDate();
for(Issue subtask : parentIssue.getSubTaskObjects())
if( ( subtask.getDueDate() != null ) && (subtask.getDueDate().after(maxSubtakDueDate)))
maxSubtakDueDate = subtask.getDueDate();
//Update parent if requred
if( parentIssue.getDueDate().before(maxSubtakDueDate)){
parentIssue.setDueDate(maxSubtakDueDate);
//This line is not requred into postfunction also
ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(), parentIssue,EventDispatchOption.ISSUE_UPDATED, false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment