Open sani-d opened 1 week ago
def issueKey = issue.key
// Fetch the issue details from the Jira REST API def result = get("/rest/api/2/issue/${issueKey}") .header("Content-Type", "application/json") .asObject(Map)
// Ensure the request was successful if (result.status == 200) { def issueDetails = result.body def summary = issueDetails.fields.summary def subtaskType = issueDetails.fields.issuetype.subtask def issueType = issueDetails.fields.issuetype.name def reporterId = issueDetails.fields.reporter?.accountId def customNumber = issueDetails.fields?.customfield_10097 // number field
logger.warn("Subtask type: ${subtaskType}, Issue type: ${issueType}, Reporter ID: ${reporterId}, Custom number: ${customNumber}")
// Find the first comma in the summary
def commaIndex = summary.indexOf(',')
if (commaIndex != -1) {
// Get the part after the first comma, trimming leading and trailing whitespace
def summaryAfterComma = summary.substring(commaIndex + 1).trim()
// Check the conditions for sending the notification
if (issueType == "Story" &&
!subtaskType &&
reporterId == '6305b88c958ffd78c6e0e59e' &&
(customNumber == 4.0 || customNumber == 3.101 || customNumber == 3.102)) {
// Attempt to send the notifications directly with email addresses
def notifyResponse = post("/rest/api/2/issue/${issueKey}/notify")
.header("Content-Type", "application/json")
.body([
subject: "${summaryAfterComma} Blocked Faster Payment",
htmlBody: "issueDetails.fields.description,",
to: [
users: [
[
accountId: '6305b88c958ffd78c6e0e59e'
],
[
accountId: "63d0b9efa197e05f9dadb169"
]
]
]
])
.asString()
if (notifyResponse.status == 204) {
logger.info("Notifications sent successfully")
} else {
logger.warn("Failed to send notifications: Status ${notifyResponse.status} - ${notifyResponse.body}")
}
} else {
logger.warn("Conditions for sending the notifications were not met")
}
} else {
// No comma in the summary
logger.warn("Summary does not contain a comma")
}
} else { // Log error details for failed requests logger.warn("Failed to fetch issue details: Status ${result.status} - ${result.body}") }
def issueKey = issue.key // Fetch the issue details from the Jira REST API def result = get('/rest/api/2/issue/' + issueKey) .header('Content-Type', 'application/json') .asObject(Map)