Originally asked by Daniel Szewczyk on 15 April 2020 (original question)
Could you please advise how to improve the following code which we use to sync the statuses between two separate Jira instances and projects?
Also, is there a way to prevent a situation where ticket would get out of sync if there is an unhandled status on either side?
Hereâs the current code we use for handling the status syncs:
// the transitionmap maps remote statuses to transitions which needs to be activated locally
def transitionMap = [
âOpenâ:âOpenâ,
âIn Progressâ:âIn progress (2)â,
âWaiting for customerâ:âOn Hold - Pending Customerâ,
âEscalatedâ:âEscalatedâ,
âReopenedâ:âReopenedâ,
âClosedâ:âClosedâ,
]
def resolutionMap = [
âDoneâ:âDoneâ,
âFixedâ:âFixedâ,
âWonât Doâ:âWonât Doâ
]
/* transition the issue to the corresponding status.
** If the remote status is null or the status is not found in the map,
** add a comment to the issue such that the configuration can be adapted.
*/
if (replica.status == null ||
replica.status.name == null ||
transitionMap.get(replica.status.name) == null) {
issue.comments = commentHelper.addComment(âRemote status is unknown or cannot be mapped - canât handle itâ, issue.comments)
} else {
workflowHelper.transition(issue, transitionMap.get(replica.status.name))
if (replica.resolution != null && issue.resolution == null) {
// use âdoneâ as resolution if the remote resolution is not found
def targetResolutionName = resolutionMap[replica.resolution.name] ?: âWonât Doâ
// nodeHelper.getResolution looks up the local resolution object based on the provided name
issue.resolution = nodeHelper.getResolution(targetResolutionName)
}
else {
return
}
}
Thanks in advance for your help!Source: Jira Cloud (old community)