Bhavya-org / Scripts

0 stars 0 forks source link

slack message when labels changes #32

Open sani-d opened 3 weeks ago

sani-d commented 3 weeks ago

def issueKey = issue.key

for (item in changelog.items) { logger.info(item.field) if (item.field == "labels") { def labels = issue.fields.labels?.join(", ") println(labels)

if (labels == "lvl2-business") { def jiraResult = get("/rest/api/2/issue/${issueKey}") .header('Content-Type', 'application/json') .asObject(Map)

    if (jiraResult.status == 200) {
        def jiraFields = jiraResult.body.fields
        def webhookUrl = 'https://hooks.slack.com/services/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'

        def msg = [
            text: """${issue.fields.reporter.displayName} raised a ticket on PSO that we think should be handled by @bs2:

https://tideaccount.atlassian.net/servicedesk/customer/portal/20/${issue.key} - ${issue.fields.summary}""" ]

        post(webhookUrl)
            .header('Content-Type', 'application/json')
            .body(msg)
            .asString()
    } else {
        println "Failed to find issue: Status: ${jiraResult.status} ${jiraResult.body}"
    }
}

} }