1
0
-1
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!
    CommentAdd your comment...

    1 answer

    1.  
      2
      1
      0

      Hi Daniel,


      I summarized your scenario with the newest syntax:


      def statusMap = [
        "In Progress":"In progress (2)",
        "Waiting for customer":"On Hold - Pending Customer"
      ]
      
      if (replica.status == null ||
          replica.status.name == null ||
          statusMap.get(replica.status.name) == null) {
        issue.comments = commentHelper.addComment("Remote status is unknown or cannot be mapped - can't handle it", issue.comments)
      } else {
        issue.setStatus(statusMap[replica.status.name])
         if (replica.resolution != null && issue.resolution == null) {
            issue.resolution = replica.resolution    }
         else return;
      }


      In this case, for the status mapping I removed all the lines that were mapping the same statuses, ex: "Done":"Done", because the default behavior is that if the status is not in the mapping, it tries to set that same status.


      I removed the resolution mapping for the same reason and simplified the syntax.


      Thanks,


      André

        CommentAdd your comment...