Snow - Jira Cloud: bci

jira outgoing
replica.key            = issue.key
replica.type           = issue.type
replica.assignee       = issue.assignee
replica.reporter       = issue.reporter
replica.summary        = issue.summary
replica.description    = issue.description
replica.labels         = issue.labels
replica.comments       = issue.comments
replica.resolution     = issue.resolution
replica.status         = issue.status
replica.parentId       = issue.parentId
replica.priority       = issue.priority
replica.attachments    = issue.attachments
replica.project        = issue.project
replica.components = issue.components

replica."Assignment Group" = issue."Assignment Group"

replica.project.versions = []
replica.project.components = []
snow incoming
//debug.error("hello there")
if(firstSync){
    entity.tableName = "incident"
}

if(entity.tableName == "incident") { 
    entity.short_description = replica.summary
    entity.u_description = replica.description
    entity.attachments += replica.addedAttachments
    entity.comments += replica.addedComments
    
  //  debug.error(replica.labels.label.join(" "))
  //  entity.sys_tags = replica.labels[0]?.label
  //  entity.sys_tags = replica.labels.label.join(" ")
    
    
   entity.sys_tags = "raket"
   // replica.labels[0]?.label
    
    entity.assignment_group =  replica."Assignment Group"
    
    entity.correlation_id = replica.key
    

    
    
    entity.u_jiracomponents = replica.components.name.join(" ")
    
    
}


snow outgoing
if(entity.tableName == "incident") {
    replica.key            = entity.key
    replica.summary        = entity.short_description
    replica.description    = entity.u_description
    replica.attachments    = entity.attachments
    replica.comments       = entity.comments
    replica.state          = entity.state
    replica.tags           = entity.sys_tags 
    replica.priority = entity.priorityValue
    replica."Openend" = entity.opened_at
    replica."Assigned Group" = (entity.assignment_group instanceof Map) ? entity.assignment_group.display_value : null
    replica."AssignedTo" = nodeHelper.getTableByLink(entity?.assigned_to?.link)?.email
    replica."OpenedBy" = nodeHelper.getTableByLink(entity.opened_by?.link)?.email
    replica."u_jiracomponents" = entity.u_jiracomponents
    replica."Configuration_Item" = entity."cmdb_ci"
    replica.request_item_entity = "no"
    replica.entity_type    = entity.tableName    
}

if(entity.tableName == "sc_req_item") {
    replica.summary = entity.number
    replica.request_item_entity = "yes"
    replica.key            = entity.key
    replica.cat_item = entity."cat_item"
    replica.request = entity."request"
    replica.requested_for = nodeHelper.getTableByLink(entity.requested_for?.link)?.email
    replica.opened_at = entity."openened_at"
    replica.opened_by  = nodeHelper.getTableByLink(entity.opened_by?.link)?.email
    replica.state = entity.state
    replica.stage = entity.stage
    replica.comments       = entity.comments
    replica.description    = entity.u_description
    replica.entity_type    = entity.tableName
}

if(entity.tableName == "sc_task"){
    return
        replica.key            = entity.key
    replica.summary        = entity.short_description
    replica.description    = entity.u_description
    replica.attachments    = entity.attachments
    replica.comments       = entity.comments

if(entity.cat_item && entity.cat_item != ""){
  replica.cat_item = nodeHelper.getTableByLink(entity.cat_item?.link)?.u_jira_project
}
}
jira incoming
//debug.error("${replica.request_item_entity}")
if(firstSync){
     if(replica.entity_type == "incident"){
        
        issue.projectKey = "COM"
    issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Story"
     
     }else{
                
               def config_item = replica?."Configuration_Item"
                //remote configuration item: local project key
                def projectMapping = ["Car-1":"COM"]
                issue.projectKey   = projectMapping[config_item] ?: "COM"
                issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Bug"}
}

if(replica.entity_type == "sc_req_item"){
    issue."Assignment Group"     =     replica."Assigned Group"
    issue."Ticket Number"        =     replica.key
}


issue.summary      = replica.summary
issue.description  = replica.description
issue.comments     = commentHelper.mergeComments(issue, replica)
issue.attachments  = attachmentHelper.mergeAttachments(issue, replica)
issue.labels += nodeHelper.getLabel("${replica.tags}")

issue."Created"              =     replica."Openend" 



def component = nodeHelper.getComponent(replica."u_jiracomponents", issue)
issue.components += component


    def priorityMapping = [
         "1 - Critical": "High",
         "2 - High": "High",
         "3 - Moderate": "Medium",
         "4 - Low": "Low",
         "5 - Planning": "Lowest"
   ]
    def defaultPriority = "Low"
    def priorityName     = priorityMapping[replica.priority?.name] ?: defaultPriority 
    issue.priority = nodeHelper.getPriority(priorityName)

def defaultAssignee  =   nodeHelper.getUserByEmail("mathieu.lepoutre@idalko.com")
def openendBy = nodeHelper.getUserByEmail(replica.OpenedBy) ?: defaultAssignee

if(nodeHelper.isUserAssignable(issue.projectKey, openendBy)){
   issue."Creator"  = openendBy
} 

def requestedFor = nodeHelper.getUserByEmail(replica.requested_for) ?: defaultAssignee
if(nodeHelper.isUserAssignable(issue.projectKey, requestedFor)){
   issue."Reported By"  = requestedFor
}