Bhavya-org / Scripts

0 stars 0 forks source link

update summary #1

Open Bhavya-ss opened 1 month ago

Bhavya-ss commented 1 month ago

def issueKey = 'ROAD-73'

// Fetch the issue details using the issue key def issue = get('/rest/api/2/issue/' + issueKey) .header('Content-Type', 'application/json') .asObject(Map) .body

// Check if the description contains the specified strings if (issue.fields.description) { def description = issue.fields.description.toLowerCase().trim()

if (description.contains("hyderabad") || description.contains("india-remote")) {
    updateIssue(issueKey, "A new joiner Hyd Team", "Hyd", "6305b88c958ffd78c6e0e59e")
} else if (description.contains("delhi")) {
    updateIssue(issueKey, "A new joiner Delhi Team", "New Delhi", "63d0b9efa197e05f9dadb169")
} else if (description.contains("serbia") || description.contains("lithuania") || description.contains("sofia") || description.contains("hungary") || description.contains("ukraine") || description.contains("germany") || description.contains("romania")) {
    updateIssue(issueKey, "A new joiner Sofia Team", "Sofia", "630a0d15ec02b5f28b63a024")
} else if (description.contains("london")) {
    updateIssue(issueKey, "A new joiner London Team", "London", "6305b7edb155e59f6955bf9e")
} else {
    return 'No matching criteria found in description.'
}

} else { return 'Issue description is empty.' }

// Function to update the issue def updateIssue(issueKey, newSummary, newOffice, newAssigneeAccountId) { def officeFieldId = [ [ "value": newOffice ] ]

def result = put('/rest/api/2/issue/' + issueKey)
    .header('Content-Type', 'application/json')
    .body([
        fields:[
            summary: newSummary,
            "customfield_10246": officeFieldId
        ]
    ])
    .asString()

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

if (result.status == 204 && resultAssignee.status == 204) {
    return 'Success'
} else {
    return "${result.status}: ${result.body} | ${resultAssignee.status}: ${resultAssignee.body}"
}

}