Bhavya-org / Scripts

0 stars 0 forks source link

comment n assignee #12

Open sani-d opened 1 month ago

sani-d commented 1 month ago

def issueKey = issue.key

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()) }

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

if (["DSER (Deletion request)", "DSAR (Access request)"].contains(requestType)) { 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.")
}

def newAssigneeAccountId = '5db2e8387b20d80c2a25cbba' // Use the account ID of the new assignee 
def updateResult = put('/rest/api/3/issue/' + issueKey + '/assignee')
    .header('Content-Type', 'application/json')
    .body([
        accountId: newAssigneeAccountId
    ])
    .asString()

} else { println("Request type is not 'DSER (Deletion request)',DSAR (Access request), skipping automated comments.") }