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

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

我正在使用自动化规则并在 scriptrunner 中执行以下代码来创建新问题:

这是导致问题的代码块:

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() 的值,我得到:MOUNA CAMELIA 14 [2021 年 4 月-收件箱]

我正在打印 newissue.getComponents() 的值,并且得到:MOUNA CAMELIA 15[ProjectComponentImpl { name='NER', description='Whole Department Database', Lead='jfd', allocateeeType='1', projectId='52315',id='19852',存档='false',删除='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++

    }

}

可以采取什么措施来解决这个问题?

groovy jira jira-rest-api jira-rest-java-api scriptrunner-for-jira
1个回答
0
投票
   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[])
        }
© www.soinside.com 2019 - 2024. All rights reserved.