Bhavya-org / Scripts

0 stars 0 forks source link

Notify n assignee is request type matches #27

Open sani-d opened 3 weeks ago

sani-d commented 3 weeks ago

def issueKey = issue.key

// Notification part with request type condition def requestBody = [ subject: "${issue.key} was just created!", htmlBody: """ ${issue.fields.summary} ${issue.fields.description} """, to: [ users: [ accountId: "5f900c7c950f8c0076353201" ] ] ] def requestType = issue.fields.customfield_10848?.requestType?.name

if (requestType == "Mastercard Connect Requests") { def resp = post("/rest/api/2/issue/${issueKey}/notify") .header("Content-Type", "application/json") .body(requestBody) .asString()

// Handle notification response
if (resp.status == 200) {
    println "Notification sent successfully."
} else {
    println "Failed to send notification. Status code: ${resp.status}, Response body: ${resp.body}"
}

// Assignee update part with request type condition
def newAssigneeAccountId = '5f900c7c950f8c0076353201' // 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()

// Handle assignee update response
if (updateResult.status == 204) {
    println "Assignee updated successfully."
} else {
    println "Failed to update assignee. Status code: ${updateResult.status}, Response body: ${updateResult.body}"
}

} else { println("Request type is not 'Budget - Cost Approval', 'Budget - SSOT Change requests', 'Budget - New Headcount Request', 'PUR - New Software Budget Approval Request', 'PUR - Software Procurement Approval', 'PUR - Software Renewal Approval', skipping automated actions.") }