2017-10-17 158 views
1

我想在所有鏈接的故事和任務處於狀態「完成」時自動關閉史詩。我不擅長groovy,還是新鮮的,並試圖找到我的腳。所以,我有以下腳本:關閉史詩,當所有的故事過渡完成

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無法自動轉換。 enter image description here 以上是故事發布類型的工作流程 enter image description here 以上是史詩發佈類型。

請幫助:)

回答

0

For your warning: 而不是getStatusObject(),使用的getStatus()。它做同樣的事情,但不被棄用。

updateEpic()您有:

def result = issueService.validateTransition(currentUser, epic.id, 31, parameters) 
issueService.transition(currentUser, result) 

你的結果變量是TransitionValidationResult一個實例,實現ServiceResult。它包含警告和錯誤的集合。您應該檢查/記錄這些信息,以確定轉換過程中出現了什麼問題。要簡單地檢查您的轉換是否成功,請使用result.isValid()