我想在所有关联的故事和任务处于状态"完成"时自动关闭Epic。我不熟悉时髦,仍然新鲜,并试图找到我的脚。所以我有以下脚本:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.scriptrunner.runner.customisers.ContextBaseScript
import groovy.transform.BaseScript
import org.apache.log4j.Logger
@BaseScript ContextBaseScript context
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueService = ComponentAccessor.getIssueService()
def currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def isEpicInProgress = {Issue epic ->
if (epic.issueType.name == "Epic") {
if (epic.statusObject.name != "Done") {
return true
} else {
return false
}
}
}
def isStoryClosed = {Issue story ->
if (story.statusObject.name == "Done") {
return true
} else {
return false
}
}
def updateEpic = {Issue epic ->
if (isEpicInProgress) {
def parameters = issueService.newIssueInputParameters()
def result = issueService.validateTransition(currentUser, epic.id, 31, parameters)
issueService.transition(currentUser, result)
log.warn("Epic update to " + result)
}
}
def isEpicClosable = {Issue epic ->
def finalResult = true
issueLinkManager.getOutwardLinks(epic.id).each { link ->
def story = link.destinationObject
def closedStory = isStoryClosed(story)
finalResult = closedStory && finalResult
}
log.warn("Final result is " + finalResult);
return finalResult
}
issueLinkManager.getInwardLinks(issue.id).each { link ->
def linkTypeId = link.getLinkTypeId()
def isEpicOfLinkType = 10300
if (isEpicOfLinkType == linkTypeId) {
def epic = link.sourceObject
if (isEpicInProgress(epic)) {
if (isEpicClosable(epic)) {
updateEpic(epic)
}
}
}
}
JIRA抱怨以下内容:
不推荐使用story.statusObject.name - >我不知道如何找到新的
我得到的第二个问题是除了上述警告之外,脚本运行时不会产生任何错误,但Epic无法自动转换。 以上是故事问题类型的工作流程 以上是史诗问题类型。
请协助:)
答案 0 :(得分:0)
For your warning: 使用 getStatus()代替 getStatusObject()。它做了同样的事情,但没有弃用。
在 updateEpic()中你有:
def result = issueService.validateTransition(currentUser, epic.id, 31, parameters)
issueService.transition(currentUser, result)
您的结果变量是 TransitionValidationResult 的实例,它实现了 ServiceResult 。它包含警告和错误的集合。您应该检查/记录这些,以确定您的过渡到底出了什么问题。要简单地检查您的转换是否成功,请使用result.isValid()