Auto assign created issues to users if unassigned for more than 24 hours based on Component

- April 8, 2020

Hi all,

One of the tech leads at my job is looking to have issues in her project automatically assigned to users in rotation if left unassigned for over 24 hours. This is also to be dependent on the Component/s that the issue is listed as part of since her users support various systems/components.

I'm not the most experienced with coding, but did find this script from Scriptrunner https://library.adaptavist.com/entity/round-robin-assign-issue-to-users-in-a-certain-project-role and figured this may be near what I'm trying to accomplish. (script pasted below)

The script in the link assigns issues to users specific to a project role in round robin. This is almost what I'm looking for, except I want to set assignees based on the components listed on the issue rather than the project role listed.

What I'm thinking of doing is replacing the roleName variable with an string array of components listed for this project, and then maybe using a jqlQuery to pull a list of users that have ever been assigned to issues with said components listed, pass this list as a string array, and then use a random number constructor to randomly pick a number in that array of listed users, and with whatever number is picked, assign that user to the issue.

Now the challenge for me is to translate this into code (if even possible).

I shall post a snippet of the changes I'll be making to this, but I wanted to throw this into the Community to see if anyone had any suggestions or possibly a solution to this that may work better than what I've proposed. I'm open to anything at this point.

Thanks in advance!

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

// the role you want assignees to set from
final String roleName = "Project Role"

def issueManager = ComponentAccessor.issueManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

// get all of the users associated with the specified project role
def projectRole = projectRoleManager.getProjectRole(roleName)

// sort the users of the project role using the user key
def users = projectRoleManager.getProjectRoleActors(projectRole, issue.projectObject)
.applicationUsers
.toSorted { it.key }

// there are no users in the specific project role
if (!users) {
log.info "No users for project role $roleName"
return
}

// find the latest created issue id that has an assignee
def lastIssueIdWithAssignee = issueManager.getIssueIdsForProject(issue.projectObject.id)
.sort()
.reverse()
.find { issueManager.getIssueObject(it).assignee }

if (!lastIssueIdWithAssignee) {
issue.setAssignee(users.first())
return
}

def lastAssignee = issueManager.getIssueObject(lastIssueIdWithAssignee).assignee
def lastAssigneeIndex = users.indexOf(lastAssignee)
def nextAssignee = users[(lastAssigneeIndex + 1) % users.size()]

issue.setAssignee(nextAssignee)

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events