-
Notifications
You must be signed in to change notification settings - Fork 1
/
quien hace el ovimiento.groovy
115 lines (99 loc) · 4.31 KB
/
quien hace el ovimiento.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def issueKey = 'SDYT-40'
def statusFrom='WORK IN PROGRESS'.toLowerCase()
def statusFrom2='Pending'.toLowerCase()
def statusTo='Escalated'.toLowerCase()
//recogemos los datos de la Issue del historico de cambios
def result = get("/rest/api/2/issue/${issueKey}?expand=changelog")
.header('Content-Type', 'application/json')
.asObject(Map)
//definimos variables
def author1 = result.body.fields.assignee?.name //nombre de la persona asignada
def h = result.body.changelog.histories.size() //numero de movimientos historico
if (result.status >= 200 && result.status < 300){
logger.info("historias hechas --> " + h)
//definimos un boleano para trabajar con él
def hasTransitionToEscalated = false
//hacemos un bucle con result.body.changelog.histories y las metemos en hist
for(hist in result.body.changelog.histories){
if(hasTransitionToEscalated) break
//volvemos a hacer un bucle para preguntar sobre los items de result.body.changelog.histories
for(item in hist.items){
//preguntamos por el ststus
if(item.fieldId=="status"){
logger.info('from: '+item.fromString+', to: '+item.toString)
//si viene de pending o work in progress o esta en escalado seguimos la pregunta
if((item.fromString.toLowerCase()==statusFrom || item.fromString.toLowerCase()==statusFrom2) && item.toString.toLowerCase()==statusTo){
logger.info('Es escalado')
//trabajamos el boleano
hasTransitionToEscalated=true
break
}else{
logger.info('No es escalado de N1 a N2')
}
}
}
if(hasTransitionToEscalated == true){
logger.info("("+hist.id+")"+" ["+hist.author.name+"], ")
//definimos result.body.changelog.histories.author.name
def nom = hist.author.name
//ponemos el nombre que hemos recogido antes
def resultAssign = put("/rest/api/2/issue/${issueKey}/assignee")
.header('accept', 'application/json')
.header('Content-Type', 'application/json')
.body("{\"name\":\""+ nom +"\"}}")
.asJson()
if (resultAssign.status >= 200 && resultAssign.status < 300){
logger.info("result transicionar: " + resultAssign.status + '; ' + resultAssign.statusText)
//break
} else {
logger.info("Failed to ASSIGN issue: Status: ${resultAssign.status} ${resultAssign.body}")
}
}
}
//asignado actual
def issueKey = 'SDYT-40'
def result = get("/rest/api/2/issue/${issueKey}?expand=changelog")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
def asignado = result.body.fields.assignee
return asignado
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
//estado en el que se encuentra
def issueKey = 'SDYT-40'
def result = get("/rest/api/2/issue/${issueKey}?expand=changelog")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
def asignado = result.body.fields.status.name
return asignado
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
// buscamos el ultimo responsable
def issueKey = 'SDYT-40'
def result = get("/rest/api/2/issue/${issueKey}?expand=changelog")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
def num = result.body.changelog.histories.size()
def asignado = result.body.changelog.histories.author[num-1]
return asignado
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
//posible ultimo responsable
def issueKey = 'SDYT-40'
def result = get("/rest/api/3/issue/${issueKey}/changelog")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
def num = result.body.values.author.size()
def asignado = result.body.values.items.toString
return asignado
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
}