Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vikrantyadav11/76015401117816880a34caf8974e02d1 to your computer and use it in GitHub Desktop.
Save vikrantyadav11/76015401117816880a34caf8974e02d1 to your computer and use it in GitHub Desktop.
// 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 == "Sub-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 sub-tasks via HAPI
def subtasks = Issues.search("""parent = ${parentKey}
AND status NOT IN ("Closed", "Cancelled", "Rejected", "Done", "Canceled", "Applied in Production")""")
def subtaskSum = subtasks.collect { it.fields[storyPointsField] ?: 0 }.sum()
logger.info("Updating parent ${parentKey} with summed SP = ${subtaskSum}")
// 3. Update the parent issue
put("/rest/api/3/issue/${parentKey}")
.header("Content-Type", "application/json")
.body([fields: [(storyPointsField): subtaskSum]])
.asString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment