-
Notifications
You must be signed in to change notification settings - Fork 10
/
remember-last-developer.groovy
56 lines (52 loc) · 1.82 KB
/
remember-last-developer.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
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.user.ApplicationUsers
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def result = null;
String user_to = null;
String user_from = null
int statusFound = 0;
def changedFromInProgrees = [];
def changedFromInProgreesId = [];
def lastChangeId
def changes = changeHistoryManager.getChangeHistories(issue)
changes.eachWithIndex {
ChangeHistory change, changeId ->
def properties = change.getChangeItemBeans()
properties.each {
ChangeItemBean property ->
if (property.getField() == "status" && (property.fromString == "In Progress" || property.fromString == "Design")) {
changedFromInProgrees.push(change);
changedFromInProgreesId.push(changeId);
lastChangeId = changeId;
}
}
}
if (changedFromInProgreesId != []) {
changes.eachWithIndex {
ChangeHistory change, changeId ->
def properties = change.getChangeItemBeans()
properties.each {
ChangeItemBean property ->
if (statusFound == 0) {
if (changeId >= lastChangeId) {
if (property.getField() == "assignee") {
user_from = property.from;
user_to = property.to;
def mrBean = property;
statusFound = 1;
}
}
}
}
}
}
result = ApplicationUsers.byKey(issue.getAssigneeId())
if (user_to) {
result = ApplicationUsers.byKey(user_to)
}
if (user_from) {
result = ApplicationUsers.byKey(user_from)
}
return result;