无法使用java中的componentrestclient填充jira中的components字段

5ssjco0h  于 2021-07-05  发布在  Java
关注(0)|答案(1)|浏览(421)

在java中使用jirarestclient创建jira时,我一直在尝试不同的方法来填充components字段,但不知怎么的,我无法做到这一点。以下是我尝试过的方法之一-

public String createIssue(String projectKey, Long issueType, String issueSummary, String description) throws URISyntaxException {

    IssueRestClient issueClient = restClient.getIssueClient();
    ComponentRestClient componentClient = restClient.getComponentClient();
    String componentUrl = "https://jira.abc.com/issues/?jql=project+%3D+PROJECTKEY+AND+component+%3D+%22Comp+Name%22";
    Component component = componentClient.getComponent(new URI(componentUrl.trim())).claim();
    //BasicComponent bc = new BasicComponent();
    IssueInput newIssue = new IssueInputBuilder(projectKey, issueType, issueSummary)
            .setDescription(description).setComponents(component).build();
    return issueClient.createIssue(newIssue).claim().getKey();
}

在json解析步骤中,我得到了一个错误-

at org.codehaus.jettison.json.JSONTokener.syntaxError(JSONTokener.java:439) ~[jettison-1.1.jar:1.1]
at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:169) ~[jettison-1.1.jar:1.1]
at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:266) ~[jettison-1.1.jar:1.1]
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$1.handle(AbstractAsynchronousRestClient.java:147) ~[jira-rest-java-client-core-4.0.0.jar:?]
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:189) ~[jira-rest-java-client-core-4.0.0.jar:?]
at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$3.apply(AbstractAsynchronousRestClient.java:185) ~[jira-rest-java-client-core-4.0.0.jar:?]
at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:81) ~[atlassian-httpclient-api-0.23.0.jar:?]
at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:11) ~[atlassian-httpclient-api-0.23.0.jar:?]
at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:268) ~[atlassian-util-concurrent-2.4.2.jar:?]
at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:158) ~[atlassian-util-concurrent-2.4.2.jar:?]
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1132) ~[guava-20.0.jar:?]
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:435) ~[guava-20.0.jar:?]
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:900) ~[guava-20.0.jar:?]

任何帮助或建议将不胜感激!

bvhaajcl

bvhaajcl1#

这应该起作用:

IssueInputBuilder builder = new IssueInputBuilder( projectKey, issueType, issueSummary );

    Iterable<BasicComponent> components = restClient
            .getProject( projectKey )
            .getComponents( );

    for ( BasicComponent c : components ) {
        if ( c.getName().equals( "your component name" ) ) {
            builder.setComponents( c ); // assuming you want only one component
        }
    }

    IssueInput newIssue = builder.setDescription(description).build(); // etc...

相关问题