Skip to main content
Example scripts
arrow icon
To homepage
Jira
Cloud icon
Cloud

Automatically tag users from group except assignee in comment on selected priority

Features
Listeners
Created 1 year ago, Updated 6 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira
Language |
groovy
final GROUP_NAMES = ["jira-project-leads"]

def issueKey = issue.key
def assignee = issue.fields.assignee

def priorityChange = changelog?.items.find { it['field'] == 'priority' }

if (!priorityChange) {
    logger.info("Priority was not updated")
    return
}
logger.info("Priority changed from {} to {}", priorityChange.fromString, priorityChange.toString)

if (priorityChange.toString == "Highest") {
    def userListFromGroup = []

    GROUP_NAMES.each { groupName ->
        def groupMembers = Groups.getByName(groupName).getMembers()
        userListFromGroup.addAll(groupMembers)
    }

    def tags = userListFromGroup.findAll { user -> user.accountId != assignee.accountId }.collect { user ->
        [
            "type": "mention",
            "attrs": [
                "id": user.accountId,
                "text": "@" + user.displayName,
                "accessLevel": ""
            ]
        ]
    }

    def body = [ "body": [
        "version": 1,
        "type": "doc",
        "content": [
            [
                "type": "paragraph",
                "content": tags + [
                    [
                        "type": "text",
                        "text": " This issue requires your attentions."
                    ]
                ]
            ]
        ]
    ]]

    def postCommentResp = post("/rest/api/3/issue/${issueKey}/comment")
        .header('Content-Type', 'application/json')
        .body(body)
        .asObject(Map)

    assert postCommentResp.status == 201
}
Having an issue with this script?
Report it here