if(newIssueproject.getVersions().contains(v)) 总是返回 false,尽管它应该是 true

问题描述 投票:0回答:1

仅当特定项目具有与当前问题相同的版本时,我才尝试创建新版本。这里是在以下代码块中制作的:

for( Version v: issue.getFixVersions()){

                        if(newIssueproject.getVersions().contains(v)){

                                 Version mynewVersion= ComponentAccessor.versionManager.createVersion(v.getName()+"-Inbox", startDate, releaseDate, description, newIssueproject.id, scheduleAfterVersion, released)

                                 mynewVersions.add(mynewVersion)

                        }

问题是

if(newIssueproject.getVersions().contains(v))
总是返回 false,尽管有时它应该是 true。结果,我的版本总是为空。那么如何解决这个问题呢?

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def authenticationContext = ComponentAccessor.jiraAuthenticationContext

def issueFactory = ComponentAccessor.getIssueFactory()

def issueManager = ComponentAccessor.getIssueManager()

def userManager = ComponentAccessor.getUserUtil()

 def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

long issueLinkType= 10070 as long

long sequence =1 as long

long newissueTypeID= 19 as long

long myissueID= issue.getId() as long

// the key of the project under which the version will get created

 final String projectKey = "SF"

// 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"

def projectComponentManager = ComponentAccessor.getProjectComponentManager()

         int counter=0

        for(ProjectComponent component: componentList){

                    MutableIssue newissue= ComponentAccessor.issueFactory.getIssue()

                                        //set values

                    newissue.setProjectObject(issue.projectObject)

                    newissue.setIssueTypeId("19") 

                    newissue.setSummary("MOUNA CAMELIA")

                    newissue.setDescription("MOUNA CAMELIA")

                    newissue.reporter = issue.getReporter()

                    String componentName= component.getName()

                    log.warn("MOUNA CAMELIA HELLO 5 "+component)

                    def shortenedComponentName = componentName.substring(componentName.indexOf("-")+1) 

                    def projectName = componentName.substring(0, componentName.indexOf("-")) 

                    log.warn("MOUNA CAMELIA HELLO 6 projectName--"+projectName+"--" )

                    def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)

                    newissue.setProjectObject(newIssueproject)

                    log.warn("MOUNA CAMELIA ISSUE GET VERSIONS "+newIssueproject.getVersions()+"-========= "+issue.getFixVersions())

                    def mynewVersions = new ArrayList <Version> ()

                    for( Version v: issue.getFixVersions()){

                        if(newIssueproject.getVersions().contains(v)){

                                 Version mynewVersion= ComponentAccessor.versionManager.createVersion(v.getName()+"-Inbox", startDate, releaseDate, description, newIssueproject.id, scheduleAfterVersion, released)

                                 mynewVersions.add(mynewVersion)

                        }

                

                    }

                    newissue.setFixVersions(mynewVersions)
groovy jira jira-rest-api jira-plugin scriptrunner-for-jira
1个回答
0
投票

根据 javadoc 看起来版本可以通过 ID 或名称进行比较

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/project/version/Version.html

字段摘要:NAME_COMPARATOR、ID_COMPARATOR

如果您想按版本名称进行比较,您的代码可能如下所示:

def matchedVersions = issue.getFixVersions().intersect(
        newIssueproject.getVersions(), 
        Version.NAME_COMPARATOR 
    )
© www.soinside.com 2019 - 2024. All rights reserved.