Answer by Francis Martens (Exalate) on 13 February 2020
What about
UNTESTED
def workflowMap = [
"Open" : "Under Review",
"Accepted" : "Under Review",
"Done" : "Fixed"
]
if (replica.status.name != "Done" || replica.fixVersions != null) {
// don't do the status transition when the remote status is 'Done' and the fixVersions is empty
Status.receive(useRemoteStatusByDefault = true, workflowMap, [:])
}
Comments:
Berry Kersten commented on 13 February 2020
Great, thanks.
Unfortunately, it’s still doing the transition if the fixVersions is empty. However, I don’t see any value for that in the Remote Issues, so it seems to be empty.
Francis Martens (Exalate) commented on 13 February 2020
Maybe it is not really empty, but the value is null.
Can you add in your code something like
import com.exalate.api.exception.IssueTrackerException
// throw an error to be able to inspect the replicas
throw new IssueTrackerException("Fixversion = ${replica.fixVersions}")
This will generate an error. The details of the error contain the message being sent (at bottom of the page)
Berry Kersten commented on 14 February 2020
Yes indeed, that might be the issue. I’ve added the additional code, and according to the error
Script error for issue RI-4844. Details: javax.script.ScriptException: com.exalate.api.exception.IssueTrackerException: Fixversion = []. Error line: Script178.groovy:35
Berry Kersten commented on 14 February 2020
Getting closer… I tried again using
if (replica.status.name != "Done" && replica.fixVersions.isEmpty()) {
Status.receive(useRemoteStatusByDefault = true, workflowMap, [:])
}
But that’s not resulting the expected behaviour. I want that (pseudocode)
IF status DONE AND fixVersions has a value
OR IF any other status AND fixVersions is empty
THEN do the workflowmap
As I’m not a Groovy expert, I’m not sure how to do this. Any suggestions?
Francis Martens (Exalate) commented on 14 February 2020
I guess you’re almost there - can you try
def workflowMap = [
"Open" : "Under Review",
"Accepted" : "Under Review",
"Done" : "Fixed"
]
if (replica.status.name != "Done" || replica.fixVersions?.size() > 0) {
// don't do the status transition when the remote status is 'Done' and the fixVersions is empty
Status.receive(useRemoteStatusByDefault = true, workflowMap, [:])
}
Berry Kersten commented on 17 February 2020
Francis Martens (Exalate)
Thanks for the new suggestion. However, unfortunately that does not work: when the status is set to Done AND FixVersions is empty, then the sync is performed (including workflowmapping).
I also tried the operator != but that didn’t work as well. Even tried == and < (for testing a negative flow).
Just thinking out loud Maybe we should include some kind of other check first, like
def emptyList = fixVersions.isEmpty
if (replica.status.name != "Done" || emptyList = false )
Francis Martens (Exalate) commented on 17 February 2020
Yes - this might work - small suggestion …
if (replica.status.name != "Done" || !replica.fixVersions?.isEmpty) ...
Berry Kersten commented on 18 February 2020
I found out that something else was wrong the config…
The suggestion if (replica.status.name != “Done” || replica.fixVersions?.size() > 0) { works!
Francis Martens (Exalate) commented on 18 February 2020
aha - nice to know