I am using an automation rule and I have used issue updated as an automation trigger for my rule and it's not working, I receive the message, the issue does not have any components even though the issue does have components.
You can see it in these screenshots:
Here is the code which is supposed to be executed based on an issue update. I printed the issue and I have gotten the following: =====MOUNA CAMELIA ISSUE:::: SF-437 ISSUE COMPONENTS []
The issue components are empty which is obviosuly wrong. My issue does have components.
package SuperFeature
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
def log = Logger.getLogger('atlassian-jira.log')
List < String > componentList = new ArrayList < String > ()
List < ProjectComponent > finalComponentList = new ArrayList < ProjectComponent > ()
def projectNames = [ 'WF', 'BF', 'EF', 'YF', 'CLTF']
log.warn("=====MOUNA CAMELIA ISSUE:::: "+ issue +" ISSUE COMPONENTS "+issue.getComponents())
if (issue.getComponents().size() == 0) {
issue.update {
String text = "Issue does not have any components\n"
setCustomFieldValue('Execution Summary', text )
}
} else if (issue.getFixVersions().size() == 0) {
issue.update {
String text = "Issue does not have any fix versions\n"
setCustomFieldValue('Execution Summary', text)
}
} else {
int componentSize = issue.getComponents().size()
int generatedIssuesCounter= 0
for (ProjectComponent component: issue.getComponents()) {
String componentName = component.getName()
def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)
def projectName = componentName.substring(0, componentName.indexOf("-"))
if(projectNames.contains(projectName)){
def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)
//log.warn("MOUNA CAMELIA found--"+found+"--NEW LIST SIZE: "+newList)
List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents());
def found = newList.any {
it.getName().equals(shortenedComponentName)
}
if (found) {
componentList.add(componentName+" ===> WILL BE GENERATED")
finalComponentList.add(component)
generatedIssuesCounter++
} else{
componentList.add(componentName+" ===> CANNOT BE GENERATED")
}
}
}
issue.update {
String text = "The super feature " + issue + " will be split into " + generatedIssuesCounter + " features, one for each component:\n"
text = text + componentList.join("\n") ;
// Partition a list into list of lists size 3
setCustomFieldValue('Execution Summary', text)
}
}