DevGenius1 / Scripts

1 stars 1 forks source link

Daily remainder for assignee #24

Open sani-d opened 5 months ago

sani-d commented 5 months ago

def jqlQuery = 'project = "MS" AND cf[14622] = "Daily"'

// Step 1: Search for issues matching the JQL query def searchUrl = "/rest/api/3/search?jql=${URLEncoder.encode(jqlQuery, 'UTF-8')}" def searchResult = get(searchUrl) .header('Content-Type', 'application/json') .asObject(Map)

if (searchResult.status == 200 && searchResult.body.containsKey('issues')) { def issues = searchResult.body.issues

issues.each { issue ->
    def issueKey = issue.key

    // Only execute the action if project is "JP" and radioButton is "a"
    println("Condition met. Executing action...")

    def assignee = issue.fields.assignee?.accountId
    println(assignee)
    def resp = post("/rest/api/2/issue/${issueKey}/notify")
        .header("Content-Type", "application/json")
        .body([
            subject: "BAU Daily Task Reminder",
            htmlBody: """
                ${issue.fields.summary}
                "https://tideaccount.atlassian.net/${issueKey}"   
            """,
            to: [
                users: [
                    [
                        accountId: assignee
                    ]
                ]
            ]
        ])
        .asString()

    // Handle response as needed
    println("Response: ${resp}") // Print the response for verification
}

} else { // Condition not met, do nothing or handle differently println("Condition not met. Skipping action...") }