groovy 脚本函数在Jira自动化规则上失败:IllegalArgumentException:参数数量错误

bnl4lu3b  于 7个月前  发布在  其他
关注(0)|答案(1)|浏览(67)

我试图使用HAPI API的Scripturner和我得到以下错误:

我的代码很简单,我使用以下代码:

Collection < ProjectComponent > updatedComponentList = issue.getComponents()

         updatedComponentList.removeAll(component)
   

            issue.set {
                 setComponents(updatedComponentList)
            }

字符串
我在这个链接下找到了语法:https://docs.adaptavist.com/sr4js/latest/hapi/update-issues。代码非常简单,所以我不明白为什么它不工作,我在网上查过了,它应该能工作。
如果需要的话,下面是我的全部代码:

package SuperFeature

import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
import SuperFeature.Configuration_SuperFeature
import com.adaptavist.hapi.jira.issues.delegate.AbstractIssuesDelegate
def log = Logger.getLogger('atlassian-jira.log')
List < ProjectComponent > finalComponentList = new ArrayList < ProjectComponent > ()


    int componentSize = issue.getComponents().size()
   
    int generatedIssuesCounter= 0
     for (ProjectComponent component: issue.getComponents()) {
                      String componentName = component.getName()
                    def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)
                    def projectName = componentName.substring(0, componentName.indexOf("-"))
                
                        

                        if(Configuration_SuperFeature.projectNames.contains(projectName)){

                        
                        
                                        def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)

                                        List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents());
                                            def found = newList.any {
                                                it.getName().equals(shortenedComponentName)
                                            }
                                            if (found) {
                                                finalComponentList.add(component)
                                                generatedIssuesCounter++
                                            } 
                        }
            
     }

    createFeature(issue, finalComponentList)

void createFeature(Issue issue, Collection < ProjectComponent > componentList) {
    JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
   

    long issueLinkType = Configuration_SuperFeature.hierarchyIssueLinkType as long
    long sequence = Configuration_SuperFeature.sequence as long
    long myissueID = issue.getId() as long
    // the key of the project under which the version will get created
    final String projectKey = Configuration_SuperFeature.projectKey 
    // the start date - optional
    final Date startDate = null
    // the release date - optional
    final Date releaseDate = null
    // a description for the new version - optional
    final String description = null
    // id of the version to schedule after the given version object - optional
    final Long scheduleAfterVersion = null
    // true if this is a released version
    final boolean released = false
    def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey)
    assert project: "Could not find project with key $projectKey"
    ProjectComponentManager projectComponentManager = ComponentAccessor.getProjectComponentManager()

    Collection < ProjectComponent > updatedComponentList = issue.getComponents()
    for (ProjectComponent component: componentList) {
       
        String componentName = component.getName()
        def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)
        def projectName = componentName.substring(0, componentName.indexOf("-"))
       
        def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)
        List < String > newIssueProjectVersionIDs = new ArrayList < String > ()
        newIssueProjectVersionIDs = newIssueproject.getVersions().collect {
            it.getName()
        }
       
        def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(Configuration_SuperFeature.investmentAreaCustomField); 
        def value = issue.getCustomFieldValue(customField);
        
        
         def matchedVersions = issue.getFixVersions().intersect(newIssueproject.getVersions(), Version.NAME_COMPARATOR)

       
        
       
       
        ProjectComponent newComponent = projectComponentManager.findByComponentName(newIssueproject.getId(), shortenedComponentName)
       
     
        def componentArray = new String[1]
        componentArray[0]=newComponent.getName()
       
       
        def versionCreator = ComponentAccessor.versionManager.&createVersion.rcurry(startDate, releaseDate, description, newIssueproject.id, scheduleAfterVersion, released)
        def mynewVersions = issue.fixVersions.intersect(newIssueproject.versions, Version.NAME_COMPARATOR).collect {
            versionCreator it.name + '-Inbox'
        }
     
        


        //  long newIssueCreatedID = newissue.getId() as long
        // def labelManager = ComponentAccessor.getComponent(LabelManager)
        // labelManager.addLabel(authenticationContext.getLoggedInUser(), newIssueCreatedID, "SF-Child", false)
       

        // updatedComponentList.removeAll(component)
        // projectComponentManager.updateIssueProjectComponents(issue, updatedComponentList)
         updatedComponentList.removeAll(component)
        // issue.setComponents(updatedComponentList)

                //     issue.update {
                //     setComponents(updatedComponentList)
                // }

                issue.set {
                     setComponents(updatedComponentList)

            }
        Issue newissue = Issues.create(projectName, 'Feature') {
            setSummary("["+shortenedComponentName+"] "+issue.getSummary())
            setDescription("This feature has been generated as child of a super feature. Please use this text area to add child feature specific information.")
            setReporter(authenticationContext.getLoggedInUser())
            setCustomFieldValue(customField.getFieldName(), value)
            setFixVersions(mynewVersions as String[])
            setComponents (componentArray as String[])
            setLabels(["SF-Child"] as String [])
        }

                newissue.link(Configuration_SuperFeature.hierarchyIssueLinkType, issue)

    }
}

dldeef67

dldeef671#

解决方案是对setComponents使用强制转换

issue.update {
                setComponents(updatedComponentList as ProjectComponent[])
  }

字符串

相关问题