Snippets

Adaptavist ScriptRunner for Jira Cloud: Get a report of how many issues each user has assigned to them within a sprint

Created by Kristian Walker last modified
/*
* This example script console script can be run in the in the script console inside ScriptRunner for Jira Cloud in order to see how many issues each user has assigned to them in a sprint. 
* "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner
* license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or
* amended and must be included in any circumstances where the code snippet is shared by You or a third party." 
*/

def projectKey = "<ProjectKeyHere>"; // Specify the project key here

def jqlQuery = "project = ${projectKey} AND sprint in openSprints() and statusCategory not in (Done)";

def searchRequest = get("/rest/api/2/search")
        .queryString("jql", jqlQuery)
        .queryString("fields", "status, assignee, key")
        .asObject(Map);

// Assert that the API call to the search API returned a success response        
assert searchRequest.status == 200;

// Extract the issue properies returned from the search results to a List
def issues = (List<Map<String, Object>>) searchRequest.body.issues;

// Call the returnSprintReport utility method passing it the list
returnSprintWorkloadReport(issues);

// A utility method that returns the sprint report information. 
def returnSprintWorkloadReport(List<Map<String, Object>> issues) {

// Loop over all issues and log out a report to the Logs detailing who is assigned to each issue and what status it is in.
// as well as to construct an object of how many issues each assignee has in descending order including unassigned issues and display this information. 
    return issues.groupBy { issue ->
        println("${issue.key} is assigned to ${issue.fields.assignee?.displayName ?: 'Unassigned'} and is in the ${issue.fields.status.name} status.")
        ((Map<String, Map>) issue.fields).assignee?.displayName ?: 'Unassigned'
    }.collectEntries { assignee, issueList ->
        [(assignee): issueList.size()]
    }.sort({ a, b -> b.value <=> a.value })
};

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.