I have this for the StoryPoints, I hope it helps you get started
You would have to make the ID changes and modify it if you need something extra
What it does is calculate the Story Points of all the tasks that the EPIC has, add them and place them in the Story Points field of the EPIC
---------------------------------------------------------------------
import org.slf4j.LoggerFactory
import groovy.json.JsonSlurper
def logger = LoggerFactory.getLogger(this.class)
def issueKey = issue.key
def getEpicIssueKey = { issueId ->
def response = get("/rest/api/3/issue/${issueId}?fields=customfield_10014")
.header('Content-Type', 'application/json')
.asString()
if (response.status == 200) {
def jsonResponse = new JsonSlurper().parseText(response.body)
return jsonResponse.fields.customfield_10014 ?: issueId
}
null
}
def updateEpicCustomField = { epicKey, value ->
def body = [fields: [customfield_10028: value]]
def response = put("/rest/api/3/issue/${epicKey}")
.header('Content-Type', 'application/json')
.body(body)
.asString()
if (response.status == 204) {
logger.info("Custom field updated successfully for epic ${epicKey} with value ${value}.")
} else {
logger.error("Error updating custom field for epic ${epicKey}. Status: ${response.status}, Message: ${response.body}")
}
}
def fetchAndSumCustomFieldValues = { epicKey ->
double totalValue = 0.0
def response = get("/rest/api/3/issue/${epicKey}?expand=changelog")
.header('Content-Type', 'application/json')
.asString()
if (response.status == 200) {
def jsonResponse = new JsonSlurper().parseText(response.body)
def changelog = jsonResponse.changelog.histories
if (changelog) {
changelog.each { entry ->
entry.items.each { item ->
if (item.field == "Epic Child" && item.toString) {
def childIssueUrl = "/rest/api/3/issue/${item.toString}?fields=customfield_10028"
def childResponse = get(childIssueUrl)
.header('Content-Type', 'application/json')
.asString()
if (childResponse.status == 200) {
def childJsonResponse = new JsonSlurper().parseText(childResponse.body)
def fieldValue = childJsonResponse.fields.customfield_10028 as Double
if (fieldValue) {
totalValue += fieldValue
}
}
}
}
}
logger.info("Total value of customfield_10028 for all child issues of ${epicKey}: ${totalValue}")
updateEpicCustomField(epicKey, totalValue)
} else {
logger.info("No changelog entries found for epic ${epicKey}.")
}
} else {
logger.error("Error retrieving epic details. Status: ${response.status}, Message: ${response.body}")
}
totalValue
}
def epicIssueKey = getEpicIssueKey(issueKey)
if (epicIssueKey) {
def totalValue = fetchAndSumCustomFieldValues(epicIssueKey)
logger.info("Total value of customfield_10028 from epic ${epicIssueKey}: ${totalValue}")
} else {
logger.error("Failed to determine the epic association for issue ${issueKey}.")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.