We use a Listener Script to sum the total Story Points up tp the Epic. Lately we have been seeing an error that we have not been able to debug. It does not happen for every issue.
The error:
ERROR - Cannot get property 'issues' on null object on line 13
The code:
// Get the ID of the fields for Story Points and Epic Link
def storyPointsField = get("/rest/api/2/field").asObject(List).body.find {(it as Map).name == 'Story Points'}.id
def epicLinkField = get("/rest/api/2/field").asObject(List).body.find {(it as Map).name == 'Epic Link'}.id
def storyPointsTotalField = get("/rest/api/2/field").asObject(List).body.find {(it as Map).name == 'Story Points Total'}.id
// Retrieve all the issues in this issues' Epic
def epicKey = issue.fields."${epicLinkField}"
def storyPoints = issue.fields."${storyPointsField}"
logger.info("Epic Key is: " + epicKey)
logger.info("Story Point is: " + storyPoints)
if (epicKey != null) { //This is to check if the event.issue's epic is null or not
def issuesInEpic = get("/rest/agile/1.0/epic/${epicKey}/issue")
.asObject(Map)
.body
.issues as List<Map>
logger.info("Total issues in Epic for ${epicKey}: ${issuesInEpic.size()}")
// Sum the estimates
def estimate = issuesInEpic.collect { Map issueInEpic ->
issueInEpic.fields."${storyPointsField}" ?: 0
}.sum()
logger.info("Summed estimate: ${estimate}")
// Now update the parent Epic
def result = put("/rest/api/2/issue/${epicKey}")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
"${storyPointsTotalField}": estimate,
]
])
.asString()
// check that updating the parent issue worked
assert result.status >= 200 && result.status < 300
}
The error occurs at the bolded line in the code. I am looking for help on two items:
1. How do I debug the issue to see which issue/field is returning a null value
2. Can I limit the data being returned to just the Story Points field and would that help resolve the null "issues" error?