groovy Jira自定义脚本验证器:检查Epic中的相关问题是否“完成”

oug3syen  于 2022-11-01  发布在  其他
关注(0)|答案(2)|浏览(235)

我正在尝试编写一个工作流验证器,以确保Epic中的所有问题都处于“完成”状态。
这是我目前得到结果:

import com.opensymphony.workflow.InvalidInputException

// Set up jqlQueryParser object
jqlQueryParser = ComponentManager.getComponentInstanceOfType(JqlQueryParser.class) as JqlQueryParser
// Form the JQL query
query = jqlQueryParser.parseQuery('"Epic Link" = {{issue.key}}')
// Set up SearchService object used to query Jira
searchService = componentManager.getSearchService()
// Run the query to get all issues with Article number that match input 
results = searchService.search(componentManager.getJiraAuthenticationContext().getUser(), query, PagerFilter.getUnlimitedFilter())

if (results.getIssues().size() >= 1) {
    for (r in results.getIssues()) {
        //Here I want to check the status of all linked issues and make sure its "Done"
    }
    return invalidInputException = new InvalidInputException("Validation failure")
}
return "Validation Succes"

我在第4行遇到错误:

而且我也不确定如何从Workflow验证器部分调试它。
谢谢你!

bz4sfanl

bz4sfanl1#

您需要先导入JqlQueryParser

import com.atlassian.jira.jql.parser.JqlQueryParser

此外,除此之外,您可能还需要一些ScriptRunner documentation中提到的其他导入。
如上面链接中提到的一个例子:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// edit this query to suit
def query = jqlQueryParser.parseQuery("project = JRA and assignee = currentUser()")

def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())

log.debug("Total issues: ${search.total}")

search.results.each { documentIssue ->
    log.debug(documentIssue.key)

    // if you need a mutable issue you can do:
    def issue = issueManager.getIssueObject(documentIssue.id)

    // do something to the issue...
    log.debug(issue.summary)
}
oknrviil

oknrviil2#

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.opensymphony.workflow.InvalidInputException

// Allow logging for debug and tracking purposes
import org.apache.log4j.Level
import org.apache.log4j.Logger

// Script code for easy log identification
String scriptCode = "Check all issues in Epics are Done -"

// Setup the log and leave a message to show what we're doing
Logger logger = log
logger.setLevel( Level.ERROR )
logger.debug( "$scriptCode Triggered by $issue.key" )

def passesCondition = true
if (issue.issueType.name == 'Epic')
   {
     IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
     def found = issueLinkManager.getOutwardLinks(issue.id).any
   {
   it?.destinationObject?.getStatus().getName() != 'Done' &&
       it?.destinationObject?.getIssueType().getName() != null
   }
   logger.debug( "$scriptCode Found =  $found " )
   if (found) {
       logger.debug( "$scriptCode return false" )
       passesCondition = false
       invalidInputException = new InvalidInputException("Please make sure all linked issues are in 'Done' status")
   } else {
       logger.debug( "$scriptCode return true" )
       passesCondition = true
       }
   }
    // Always allow all other issue types to execute this transition
       else
       {
           logger.debug( "$scriptCode Not Epic return true" )
           passesCondition = true
       }

相关问题