Bhavya-org / Scripts

0 stars 0 forks source link

Comment.internal #10

Open Bhavya-ss opened 1 month ago

Bhavya-ss commented 1 month ago

import groovy.json.JsonOutput

def issueKey = "JP-111"

// Get the issue details def issueResponse = get('/rest/api/2/issue/' + issueKey) .header('Content-Type', 'application/json') .asObject(Map)

def issueDetails = issueResponse.body def reporter = issueDetails.fields.reporter def currentStatus = issueDetails.fields.status.name

// Get the comments on the issue def commentResponse = get('/rest/servicedeskapi/request/' + issueKey + '/comment') .header('Content-Type', 'application/json') .asObject(Map)

def comments = commentResponse.body.values

// Filter out only external comments (assuming external comments have public set to true) def customerComments = comments.findAll { comment -> comment.public == true && comment.author.accountId == reporter.accountId && currentStatus != "In Progress" }

if (customerComments) { customerComments.each { comment -> // Transition the issue to "Waiting for support" def transition = post("/rest/api/3/issue/${issueKey}/transitions") .header('Content-Type', 'application/json') .body([ transition: [ id: 11 // Replace with the actual transition ID for "Waiting for support" ] ]) .asString()

    println "Issue transitioned to 'Waiting for support' due to a customer comment."
    return
}

} else { println("No customer comments present.") }