through Scripting create a report that shows time in each status for issues

mummareddy supriya March 12, 2024
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import groovy.xml.MarkupBuilder

def projectKey = "EPP_SW" // Replace with your project key
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def issueManager = ComponentAccessor.getComponent(IssueManager)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def userManager = ComponentAccessor.getComponent(UserManager)

def query = jqlQueryParser.parseQuery("project = $projectKey")
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def searchResults = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

def reportData = []

searchResults.results.each { result ->
    def issue = issueManager.getIssueObject(result.issue.id)
    def statusMap = [:] as Map<Object, Integer>
    def timeInTodo = 0
    def timeInProgress = 0

    issue.getChangeHistory().reverse().each { change ->
        if (change.field == "status") {
            if (statusMap[change.fromString]) {
                if (change.fromString != change.toString) {
                    statusMap[change.fromString]++
                }
            } else {
                statusMap[change.fromString] = 1
            }
        }
    }

    def assignee = issue.getAssignee() ? userManager.getUserByKey(issue.getAssignee().key)?.getDisplayName() : "Unassigned"
    def created = issue.getCreated()
    def issueKey = issue.getKey()

    // Calculate time in Todo and time in Progress (example calculations)
    // Replace these calculations with your own logic based on issue history
    timeInTodo = 5
    timeInProgress = 10

    reportData << [issueKey, statusMap, assignee, created, timeInTodo, timeInProgress]
}

def stringWriter = new StringWriter()
def content = new MarkupBuilder(stringWriter)

content.html {
    table {
        tr {
            th("Issue Key")
            th("Status")
            th("Assignee")
            th("Created")
            th("Time in Todo")
            th("Time in Progress")
        }
        reportData.each { row ->
            tr {
                td(row[0])
                td(row[1])
                td(row[2])
                td(row[3])
                td(row[4])
                td(row[5])
            }
        }
    }
}

stringWriter.toString()

 

stringWriter.toString() for this scrip i'm facing this error .

 

Something went wrong: MissingMethodException

 

No signature of method: com.atlassian.jira.issue.search.providers.LuceneSearchProvider.search() is applicable for argument types: (com.atlassian.query.QueryImpl, com.atlassian.jira.user.DelegatingApplicationUser...) values: [{project = "EPP_SW"}, msupriya(JIRAUSER97453), com.atlassian.jira.web.bean.PagerFilter@263200bd[start=0,end=2147483647,max=2147483647]] Possible solutions: search(com.atlassian.jira.issue.search.SearchQuery, com.atlassian.jira.web.bean.PagerFilter), search(com.atlassian.jira.issue.search.SearchQuery, com.atlassian.jira.web.bean.PagerFilter, java.util.Set), search(com.atlassian.jira.issue.search.SearchQuery, org.apache.lucene.search.Collector), each(groovy.lang.Closure).can any one please suggest how to fix it

0 answers

Suggest an answer

Log in or Sign up to answer