Bhavya-org / Scripts

0 stars 0 forks source link

formate #9

Open sani-d opened 1 month ago

sani-d commented 1 month ago

import groovy.json.JsonOutput

def issueKey = issue.key def newAssigneeAccountId = '6305b88c958ffd78c6e0e59e' // Use the account ID of the new assignee

def requestType = issue.fields.customfield_10848?.requestType?.name.toString()

if (["Ask a data privacy question","Report a personal data breach","Start a DPIA","Member Support Privacy Query","Suggest a Privacy helpdesk feature","Sharing Tide personal data externally with a third-party"].contains(requestType) {
    // Update the assignee
    def resultAssignee = put('/rest/api/3/issue/' + issueKey + '/assignee')
        .header('Content-Type', 'application/json')
        .body([
            accountId: newAssigneeAccountId
        ])
        .asString()

    if (resultAssignee.status == 204) {
        println "Assignee updated successfully."

        // Send notification to approvers
        def notificationPayload = [
            subject: "A request has been raised at IT helpdesk that needs your approval.",
            textBody: "Kindly follow the link and provide a response to the request. https://tideaccount.atlassian.net/servicedesk/customer/portal/8/${issueKey}",
            to: [
                users: [
                    [accountId: "63060b97189e0a3a4ff283dc"]
                ]
            ]
        ]

        def notifyResponse = post("/rest/api/2/issue/${issueKey}/notify")
            .header("Content-Type", "application/json")
            .body(JsonOutput.toJson(notificationPayload))
            .asString()

        if (notifyResponse.status >= 200 && notifyResponse.status < 300) {
            return "Notification sent successfully."
        } else {
            return "Failed to send notification."
        }
    } else {
        return "Failed to update assignee."
    }
}