JIRA自定义脚本验证器:检查Epic中的链接问题是否为“完成”

发布于 2025-01-27 03:02:33 字数 1189 浏览 6 评论 0原文

我正在尝试编写一个工作流验证器,以确保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行中遇到了错误:

,我也不确定如何从工作流验证器部分进行调试。

谢谢!

I'm trying to write a workflow validator that makes sure all issues in Epic are in "Done" status.

this is what I got so far:

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"

I got error in row 4:
enter image description here

and I'm also not sure how can I debug it from the Workflow validator section.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榕城若虚 2025-02-03 03:02:33

您需要导入jqlquelyparser首先:

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

此外,除此之外,您可能需要其他一些其他导入,如 scriptrunner文档

作为上面链接中提到的一个示例:

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)
}

You need to import JqlQueryParser first:

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

Also, in addition to that, you may need some other imports as mentioned in ScriptRunner documentation.

As an example that mentioned in the link above:

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)
}

回心转意 2025-02-03 03:02:33
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
       }
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
       }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文