Created
August 22, 2025 12:14
-
-
Save vikrantyadav11/10f180bb7861a9896a253ab073b5f527 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get Story Points field ID | |
def storyPointsField = get("/rest/api/3/field") | |
.asObject(List) | |
.body | |
.find { it.name == "Story Points" } | |
.id | |
// Cast issue.key to String | |
def eventIssue = Issues.getByKey(issue.key as String) | |
def issueType = eventIssue.issueType.name | |
if (issueType in ["Task", "Story", "Design Task"]) { | |
// 1. Identify parent (using parentId → REST → key) | |
def parentId = eventIssue.parentId | |
if (!parentId) return | |
def parentRes = get("/rest/api/3/issue/${parentId}") | |
.queryString("fields", "key") | |
.asObject(Map) | |
.body | |
def parentKey = parentRes.key | |
def parentIssue = Issues.getByKey(parentKey as String) | |
// 2. Fetch childs-tasks via HAPI | |
def childIssue = Issues.search("parent = ${parentKey}") | |
def childTaskSum = childIssue.collect { it.fields[storyPointsField] ?: 0 }.sum() | |
logger.info("Updating parent ${parentKey} with summed SP = ${childTaskSum}") | |
// 3. Update the parent issue | |
put("/rest/api/3/issue/${parentKey}") | |
.header("Content-Type", "application/json") | |
.body([fields: [(storyPointsField): childTaskSum]]) | |
.asString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment