Created
August 25, 2025 05:25
-
-
Save vikrantyadav11/6b7eca3ed7f841920f3c6dfd0204142f 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 | |
| logger.info("Story Point ID : ${storyPointsField}") | |
| // 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"]) { | |
| def parentId = eventIssue.parentId | |
| if (!parentId) return | |
| // Fetch parent issue key | |
| def parentKey = get("/rest/api/3/issue/${parentId}") | |
| .queryString("fields", "key") | |
| .asObject(Map) | |
| .body | |
| .key | |
| // Initialize sum | |
| def childTaskSum = 0.0 // use Double | |
| Issues.search("parent = ${parentKey}").each { child -> | |
| // Avoid using the field ID that you retrived; use the field name directly | |
| def spValue = child.getCustomFieldValue('Story Points') | |
| def sp = spValue ? spValue.toString().toDouble() : 0 | |
| childTaskSum += sp | |
| } | |
| logger.info("Updating parent ${parentKey} with summed Story Points = ${childTaskSum}") | |
| // Update the parent issue in one operation | |
| 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