Bhavya-org / Scripts

0 stars 0 forks source link

comment #6

Open pramodhm112 opened 1 month ago

pramodhm112 commented 1 month ago

def issueKey = issue.key

def commentText1 = """ ======= AUTOMATED COMMENT ========

${reporter}, please confirm if this request is for an OPEN ACCESS, or DIRECT ACCESS member! For DA, please specify if the request is for a closed membership, in KYC or abandoned before KYC.

Thank you! """ // 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()) }

def requestType = issue.fields.customfield_10010?.requestType?.name

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("Request type is not 'Fix an account problem', skipping automated comments.") }