Hi! I am trying to write a listener/post-function which close specific related issues when parent issues status changes to "Done"
At the moment I have the following code:
def issueKey = 'elpa-78'
//get all fields from parent task
def response = get("/rest/api/2/issue/" + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
def issueSummary = response.body.fields.summary
//Determine the type of task, check if it fits the required types: "Первичное тестирование" or "Тестирование изменений"
if (response.body.fields.issuetype.name == "Первичное тестирование" || response.body.fields.issuetype.name == "Тестирование изменений") {
//If the task type is correct - check the status
if (response.body.fields.status.name == "Done") {
//If conditions above are satisfied, we parse all related tasks
response.body.fields.issuelinks.outwardIssue.each { it ->
//Determine the type of related task, check if it fits the required types: "Логика (Исходящие телеком)" or "Логика (Входящие/Other)"
if (it.fields.issuetype.name == "Логика (Исходящие телеком)" || it.fields.issuetype.name == "Логика (Входящие/Other)") {
//Check if the status of the current task matches the status "In testing"
if(it.fields.status.name == "In testing") {
transitionIssue(it.key)
PostComment(it.key, issueSummary, issueKey)
}
}
}
}
}
//changes related issues status
def transitionIssue(issueID){
post("/rest/api/2/issue/${issueID}/transitions")
.header("Content-Type", "application/json")
.body([transition: [id: 101]])
.asObject(Map)
}
//leaves a comment
def PostComment(issueID, issueSummary, issueKey) {
post("/rest/api/2/issue/${issueID}/comment")
.header('Content-Type', 'application/json')
.body([
body: """
Родительская задача: [${issueSummary}|https://neuronet.atlassian.net/browse/${issueKey}] была закрыта.
Произведен перевод действующей задачи в статус "Done"
"""
])
.asObject(Map)
}
If i run it on Scriptrunner Script Console I get the result I want: all related to parent task issues changes their status to "Done" if their current status is "In Testing" and issue types matches required types.
But if i put this code into scriptrunner listeners or post-functions (where he is supposed to work), code above close only 1 issue from all related issues and leaves no comments.
Can anyone please help me understand what is the problem in this code?
When i use it on scriptrunner listeners or post-functions i change specific lines of code:
instead of:
def response = get("/rest/api/2/issue/" + issueKey) i use:
def response = get("/rest/api/2/issue/$(issue.key}")