Sync components

Originally asked by Shadi El Sangedy on 08 April 2020 (original question)


In the external JIRA issue there is a component named “Backend”, in the internal Jira this component should be automatically changed to “API”, I tried to use the following

issue.components = replica.components
	.collect { remoteComponent ->
		nodeHelper.getComponent(
		if(remoteComponent.name == "Backend"){
			remoteComponent.name
		} else remoteComponent.name,
		nodeHelper.getProject(issue.projectKey)
		)
	}.findAll()

But it says I cannot call if in that context


Answer by Juan Grases on 12 April 2020

To map components, this should work:

def componentMap = ["Backend": "API"]
issue.components = replica.components
   .collect { remoteComponent ->
        def componentName = remoteComponent.name
		def localComponent = componentMap[componentName] ?: componentName
        nodeHelper.getComponent(
            localComponent,
            nodeHelper.getProject(issue.projectKey)
        ) 
    }.findAll()