-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsubtaskChainDateUpdater.groovy
executable file
·72 lines (57 loc) · 2.34 KB
/
subtaskChainDateUpdater.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.onresolve.jira.groovy.test.scriptfields.scripts
import com.atlassian.crowd.embedded.api.User
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.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import java.sql.Timestamp
import java.io.*;
import java.util.concurrent.*;
log.debug("Test data");
/**
* 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();
boolean containsLabel = false;
for (String label : parentIssue.getLabels()) {
if (label.contains("complex")){
containsLabel = true;
break;
}}
if(!containsLabel)
return
//variables should not be defined into loops
MutableIssue linkedIssue;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField offset = customFieldManager.getCustomFieldObject("customfield_27032")
long number = 0;
IssueManager issueManager = ComponentAccessor.getIssueManager();
User curUser = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser();
ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Sequence") {
linkedIssue = issueLink.destinationObject
log.info "got here"
number = (long) linkedIssue.getCustomFieldValue(offset)
log.debug "Issue type is : ${number}"
Timestamp dueDate = issue.getDueDate();
//I think that it is better to use Calendar to add only working days
dueDate.setTime(dueDate.getTime() + TimeUnit.DAYS.toMillis(number));
if( ( linkedIssue.getDueDate() == null ) || (linkedIssue.getDueDate().before(dueDate))) {
linkedIssue.setDueDate(dueDate)
//linked issue should be updated into a loop
issueManager.updateIssue(
curUser
, linkedIssue
, EventDispatchOption.ISSUE_UPDATED
, false)
}
}
}