groovy 即使getter返回非空值,组件列表和版本列表的值也不能显示在新创建的Jira问题上

llew8vvj  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(105)

我使用自动化规则并在scripturner中执行以下代码来创建新问题:
下面是导致问题的代码块:

Issue newissue = Issues.create(projectName, 'Feature') {
            setSummary(issue.getSummary())
            setDescription(issue.getDescription())
            setReporter(issue.getReporter())
            setCustomFieldValue(customField.getFieldName(), value)
           
 }

newissue.setFixVersions(mynewVersions)
log.warn("MOUNA CAMELIA 14"+ newissue.getFixVersions())

newissue.setComponent(mynewComponentList)
log.warn("MOUNA CAMELIA 15"+ newissue.getComponents())

我正在打印newissue.getFixVersions()的值,并得到:* 酒店MONA CAMELIA 14 [2021年4月-4月]**
我正在打印newissue.getComponents()的值,并得到:MONA CAMELIA 15[ProjectEntryentImpl { name='NER',description='Whole Department Database',lead='jfd',assigneeType='1',projectId='52315',id='19852',archived='false',deleted='false' }]
值不为空。然而,当我通过自动化规则执行代码时,我得到的组件和版本的值为空,如下所示:


打印调试值的日志:

完整代码:

package SuperFeature

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.Issue

import org.apache.log4j.Logger

import com.atlassian.jira.util.ImportUtils

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.issue.index.IssueIndexManager

import com.atlassian.jira.issue.index.IssueIndexingService

import com.atlassian.jira.event.issue.IssueEventManager

import com.atlassian.jira.event.issue.IssueEvent

import com.atlassian.jira.event.type.EventDispatchOption

import com.atlassian.jira.issue.ModifiedValue

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.issue.link.IssueLinkManager

import com.atlassian.jira.issue.link.IssueLinkTypeManager

import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent

import com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent

import org.apache.log4j.Level

import com.atlassian.jira.issue.link.IssueLinkType

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.onresolve.jira.groovy.user.FieldBehaviours

import com.onresolve.scriptrunner.db.DatabaseUtil

import groovy.transform.BaseScript

import com.atlassian.jira.issue.label.LabelManager

import com.atlassian.jira.issue.label.Label

import com.atlassian.jira.security.JiraAuthenticationContext

import com.atlassian.jira.issue.IssueFactory

import com.atlassian.jira.user.util.UserUtil

import com.atlassian.jira.user.ApplicationUser

import com.atlassian.jira.issue.comments.CommentManager;

import com.atlassian.jira.util.velocity.CommonVelocityKeys

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.project.ProjectFactory

import java.util.Collection

import java.lang.*

import java.util.*

import groovy.lang.*

import groovy.util.*

import com.atlassian.jira.project.version.VersionManager

    

def log = Logger.getLogger('atlassian-jira.log')

List < String > componentList = new ArrayList < String > ()

def authenticationContext = ComponentAccessor.jiraAuthenticationContext

if (issue.getComponents().size() == 0) {

    issue.update {

        String text = "Issue does not have any components\n"

        setCustomFieldValue('Execution Summary', text)

    }

} else if (issue.getFixVersions().size() == 0) {

    issue.update {

        String text = "Issue does not have any fix versions\n"

        setCustomFieldValue('Execution Summary', text)

    }

} else {

    int componentSize = issue.getComponents().size()

    componentList = issue.getComponents().collect {

        it.getName()

    }

    issue.update {

        String text = "The super feature " + issue + " will be split into " + componentSize + " features, one for each component:\n"

        text = text + componentList.toString() + "\n";

        setCustomFieldValue('Execution Summary', text)

    }

    createFeature(issue, issue.getComponents())

}

void createFeature(Issue issue, Collection < ProjectComponent > componentList) {

    IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();

    JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();

    IssueFactory issueFactory = ComponentAccessor.getIssueFactory();

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

    ProjectFactory projectFactory = ComponentAccessor.getProjectFactory()

        VersionManager versionManager = ComponentAccessor.getVersionManager()

    long issueLinkType = 10070 as long

    long sequence = 1 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"

    ProjectComponentManager projectComponentManager = ComponentAccessor.getProjectComponentManager()

    int counter = 0

    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("customfield_10790"); // here replace the ID with ID of your custom field.

        def value = issue.getCustomFieldValue(customField);

        

       

         def matchedVersions = issue.getFixVersions().intersect(newIssueproject.getVersions(), Version.NAME_COMPARATOR)

              

       

        ProjectComponent newComponent = null

        List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents());

        def found = newList.any {

            it.getName().equals(shortenedComponentName)

        }

        //log.warn("MOUNA CAMELIA found--"+found+"--NEW LIST SIZE: "+newList)

        if (found) {

            newComponent = projectComponentManager.findByComponentName(newIssueproject.getId(), shortenedComponentName)

        } else {

            try {

                newComponent = projectComponentManager.create(shortenedComponentName, component.getDescription(), component.getLead(), component.getAssigneeType(), newIssueproject.getId())

            } catch (Exception e) {

                log.warn("MOUNA CAMELIA EXCEPTION " + e)

            }

        }

        List < ProjectComponent > mynewComponentList = new ArrayList < ProjectComponent > ()

        mynewComponentList.add(newComponent)

       

       

        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'

        }

     

        Issue newissue = Issues.create(projectName, 'Feature') {

            setSummary(issue.getSummary())

            setDescription(issue.getDescription())

            setReporter(issue.getReporter())

            setCustomFieldValue(customField.getFieldName(), value)

           

        }

          log.warn("MOUNA CAMELIA 13")

newissue.setFixVersions(mynewVersions)

log.warn("MOUNA CAMELIA 14"+ newissue.getFixVersions())

newissue.setComponent(mynewComponentList)

log.warn("MOUNA CAMELIA 15"+ newissue.getComponents())

         

  log.warn("MOUNA CAMELIA 16 " + newissue.getComponentObjects())

         long newIssueCreatedID = newissue.getId() as long

        def labelManager = ComponentAccessor.getComponent(LabelManager)

        labelManager.addLabel(authenticationContext.getLoggedInUser(), newIssueCreatedID, "SF-Child", false)

       

       

        issueLinkManager.createIssueLink(newIssueCreatedID, myissueID, issueLinkType, sequence, authenticationContext.getLoggedInUser())

        Collection < ProjectComponent > componentList2 = issue.getComponents()

        componentList2.removeAll(issue.getComponents())

        projectComponentManager.updateIssueProjectComponents(issue, componentList2)

        counter++

    }

}

如何解决此问题?

eqqqjvef

eqqqjvef1#

Issue newissue = Issues.create(projectName, 'Feature') {
            setSummary(issue.getSummary())
            setDescription(issue.getDescription())
            setReporter(issue.getReporter())
            setCustomFieldValue(customField.getFieldName(), value)
            setFixVersions(mynewVersions as String[])
            setComponents (componentArray as String[])
        }

相关问题