开发者问题收集

JQL 在 scriptrunner 中运行良好,但当它到达特定项目时,就会中断并引发异常 NoViableAltException

2022-08-25
824

我在 ScriptRunner 中运行一些 Jira 统计信息,我想知道去年更新的问题数量。我的脚本对许多项目都运行良好,除了我遇到的 1 个特定项目。我遇到了一个异常,我真的不知道为什么,因为 JQL 查询对所有其他项目都运行良好。下面是我的代码:

这是我得到的异常: 2022-08-25 16:16:46,273 错误 [common.UserScriptEndpoint]:脚本控制台脚本失败: groovy.lang.MissingMethodException:没有方法签名:com.sun.proxy。$Proxy128.search() 适用于参数类型:(com.atlassian.jira.user.DelegatingApplicationUser、String、com.atlassian.jira.web.bean.PagerFilter) 值:[mouh(JIRAUSER65000),,com.atlassian.jira.web.bean.PagerFilter@1c986119[start=0,end=2147483647,max=2147483647]] 可能的解决方案: search(com.atlassian.jira.user.ApplicationUser, com.atlassian.query.Query, com.atlassian.jira.web.bean.PagerFilter), each(groovy.lang.Closure) at com.atlassian.jira.bc.issue.search.SearchService$search$3.call(Unknown Source) at Script942.run(Script942.groovy:65)

我的 try catch 语句中也出现了异常 2022-08-25 16:16:46,258+0200 https-openssl-nio-443-exec-25 WARN mouh 976x7083017x3 15vdzc9 10.21.32.10 /rest/scriptrunner/latest/user/exec/ [atlassian-jira.log] MounaException com.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: NoViableAltException(17@[])

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger;
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.web.bean.PagerFilter
import java.text.SimpleDateFormat
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.DelegatingApplicationUser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.issue.search.SearchException

def log = Logger.getLogger("atlassian-jira.log")

List<Project> prList = ComponentAccessor.getProjectManager().getProjectObjects()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

log.warn("Project category|Project name|Last Date Updated| Number of issues|Project Lead|Admin List")
def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService.class)
ApplicationUser  user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def emptyList = []

for(Project myproject: prList){
    def lastUpdatedDate = new Date(Long.MIN_VALUE)
    def builder = JqlQueryBuilder.newBuilder()
    builder.where().project(myproject.id)
    def query = builder.buildQuery()
    def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
  
    def lastUpdated =""
    if (results.getTotal() == 0) {
        emptyList.add(myproject.getName())
        log.warn("Empty project")
    }
    else {
       
        def i = 0
        for (Issue issue : results.getResults())
        {
             lastUpdated = issue.getUpdated()
            if (i == 0 || lastUpdated > lastUpdatedDate)
                lastUpdatedDate = lastUpdated
            i++
        }
        log.warn("project key: "+myproject.getKey())
        def query2 = ""
        try{
         query2 = jqlQueryParser.parseQuery("project = "+myproject.getKey()+" and updated < 2021-08-25 ")

        }catch(Exception e){
            log.warn("MounaException "+e)
        }

        def search = searchService.search(user, query2, PagerFilter.getUnlimitedFilter())
        log.warn("Updated issues in the last year: ${search.total}"+" project "+myproject.getKey()+"/"+results.getTotal() )

    


    
    }
    
    def projectCategory=""
    if(myproject.getProjectCategory()!=null){
        projectCategory=myproject.getProjectCategory().getName()
    }

       def admins= getAdmins(projectRoleManager, myproject, user, projectManager)
        def lastDate= new SimpleDateFormat("dd/MMM/yy").format(lastUpdatedDate)
        log.warn("oo|"+projectCategory+"|"+myproject.getName()+"|"+lastDate + "|"+results.getResults().size() + "|"+ myproject.getProjectLead().getName() +"|"+admins)
       
    
}
     log.warn("Empty projects: "+ emptyList.size()+"/"+prList.size() +" "+emptyList)


def getAdmins(ProjectRoleManager projectRoleManager, Project myproject, ApplicationUser user,  ProjectManager projectManager ){


def adminProjects = []

ProjectRole projectRole = projectRoleManager.getProjectRole("Administrators")

 def projectRoles = projectRoleManager.getProjectRoles(user, myproject)
  Project project = projectManager.getProjectObjByKey(myproject.getKey())
   def result =""
    if (project) {
        ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(projectRole, project)
        result += " ${actors.getUsers()*.name}\n"
    }
    return result

}

这是我的日志文件的副本,正如您所见,我在其中进行了所有打印,除了进入 CF 项目时,一切都运行正常。有人知道应该修复什么吗?我尝试在查询中使用 project.getName() 代替 project.getKey(),但没有任何变化,仍然不起作用

2022-08-25 16:16:46,258 WARN [atlassian-jira.log]: project key: CF
2022-08-25 16:16:46,258 WARN [atlassian-jira.log]: MounaException com.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: NoViableAltException(17@[])
2022-08-25 16:16:46,273 ERROR [common.UserScriptEndpoint]: *************************************************************************************
2022-08-25 16:16:46,273 ERROR [common.UserScriptEndpoint]: Script console script failed: 
groovy.lang.MissingMethodException: No signature of method: com.sun.proxy.$Proxy128.search() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, String, com.atlassian.jira.web.bean.PagerFilter) values: [mouh(JIRAUSER65000), , com.atlassian.jira.web.bean.PagerFilter@1c986119[start=0,end=2147483647,max=2147483647]]
Possible solutions: search(com.atlassian.jira.user.ApplicationUser, com.atlassian.query.Query, com.atlassian.jira.web.bean.PagerFilter), each(groovy.lang.Closure)
    at com.atlassian.jira.bc.issue.search.SearchService$search$3.call(Unknown Source)
    at Script942.run(Script942.groovy:65)

我通过搜索问题直接在 Jira 中运行查询,如您所见,它运行正常 在此处输入图像描述

我尝试在代码中使用 myproject.getName(),但没有起作用。

2个回答

我发现了问题,我需要使用引号并使用 myproject.getName()。此行解决了该问题: jqlQueryParser.parseQuery("project = \""+myproject.getName()+"\" and updated > 2021-08-25 ")

以下是完整代码:

 import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger;
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.web.bean.PagerFilter
import java.text.SimpleDateFormat
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.DelegatingApplicationUser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.issue.search.SearchException

def log = Logger.getLogger("atlassian-jira.log")

List<Project> prList = ComponentAccessor.getProjectManager().getProjectObjects()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

log.warn("Project category|Project name|Last Date Updated| Total issues|Number of issues updated in the last year|Project Lead Display Name|Project Lead Key|Number of Admins|Admin List")
def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService.class)
ApplicationUser  user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def emptyList = []

for(Project myproject: prList){
    def lastUpdatedDate = new Date(Long.MIN_VALUE)
    def builder = JqlQueryBuilder.newBuilder()
    builder.where().project(myproject.id)
    def query = builder.buildQuery()
    def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
    int issuesUpdatedInLastYear=0; 
    def lastUpdated =""
    if (results.getTotal() == 0) {
        emptyList.add(myproject.getName())
        log.warn("Empty project")
    }
    else {
       
        def i = 0
        for (Issue issue : results.getResults())
        {
             lastUpdated = issue.getUpdated()
            if (i == 0 || lastUpdated > lastUpdatedDate)
                lastUpdatedDate = lastUpdated
            i++
        }
        log.warn("project key: "+myproject.getKey()+" "+myproject.getName())
        def query2 = ""
        try{
         query2 = jqlQueryParser.parseQuery("project = \""+myproject.getName()+"\" and updated > 2021-08-25 ")

        }catch(Exception e){
            log.warn("MounaException "+e)
        }

        def search = searchService.search(user, query2, PagerFilter.getUnlimitedFilter())
        log.warn("Updated issues in the last year: ${search.total}"+" project "+myproject.getKey()+"/"+results.getTotal() )
        issuesUpdatedInLastYear=search.total
    


    
    }
    
    def projectCategory=""
    if(myproject.getProjectCategory()!=null){
        projectCategory=myproject.getProjectCategory().getName()
    }
       ( admins, adminSize)= getAdmins(projectRoleManager, myproject, user, projectManager)
        def lastDate= new SimpleDateFormat("dd/MMM/yy").format(lastUpdatedDate)
        log.warn("bb|"+projectCategory+"|"+myproject.getName()+"|"+lastDate + "|"+results.getResults().size()+ "|"+issuesUpdatedInLastYear+ "|"+ myproject.getProjectLead().getDisplayName()+ "|"+ myproject.getProjectLead().getKey() +"|"+adminSize+"|"+admins)
       
    
}
     log.warn("Empty projects: "+ emptyList.size()+"/"+prList.size() +" "+emptyList)


def getAdmins(ProjectRoleManager projectRoleManager, Project myproject, ApplicationUser user,  ProjectManager projectManager){


def adminProjects = ""

ProjectRole projectRole = projectRoleManager.getProjectRole("Administrators")

 def projectRoles = projectRoleManager.getProjectRoles(user, myproject)
  Project project = projectManager.getProjectObjByKey(myproject.getKey())
   
    if (project) {
        ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(projectRole, project)
        adminProjects=actors.getUsers()*.name
        adminSize=actors.getUsers().size()
        log.warn("ADMIN SIZE "+adminSize)
    }
    return [adminProjects, adminSize]

}
منى
2022-08-25

这很奇怪。我原本以为密钥是搜索的最佳对象,因为它们不需要转义

mdoar
2022-08-25