if (requestType == "Fix an account problem") {
if (!commentAlreadyExists) {
// Step 4: Add the new comment only if it doesn't already exist
def addCommentResult = post('/rest/api/2/issue/' + issueKey + '/comment')
.header('Content-Type', 'application/json')
.body(["body": commentText1.trim()])
.asObject(Map)
println("Comment added. Response: ${addCommentResult}")
} else {
println("Duplicate comment found, not adding a new one.")
}
} else {
println("Condition not met, skipping the actions.")
}
def issueKey = issue.key def requestType = issue.fields.customfield_10010?.requestType?.name println(requestType)
def commentText1 = """ @james Garrington please add the requestor to the communication exclusion list https://docs.google.com/spreadsheets/d/1ai1MxigfSoGzAJWH7tV9hxCjiaJ1Esn0vRBKybrpJTk/edit#gid=0 """
// Step 2: Get existing comments for the issue def commentsResult = get('/rest/api/2/issue/' + issueKey + '/comment') .header('Content-Type', 'application/json') .asObject(Map)
// Step 3: Check for duplicate comments def comments = commentsResult.body.comments def commentAlreadyExists = comments.any { comment -> comment.body.contains(commentText1.trim()) }
if (requestType == "Fix an account problem") { if (!commentAlreadyExists) { // Step 4: Add the new comment only if it doesn't already exist def addCommentResult = post('/rest/api/2/issue/' + issueKey + '/comment') .header('Content-Type', 'application/json') .body(["body": commentText1.trim()]) .asObject(Map)
} else { println("Condition not met, skipping the actions.") }