【问题标题】:How to retrieve specific JIRA Fields in Java using RESTAPI如何使用 REST API 在 Java 中检索特定的 JIRA 字段
【发布时间】:2019-02-27 12:12:39
【问题描述】:

到目前为止,我只能与 Jira 建立连接,但我不知道如何获取特定字段。据我了解,JIRA API 的 SearchResult 类可以解决这个问题,但我不知道如何将它集成到我现有的代码中。任何帮助将非常感激。

Java 版本 - 8, 操作系统 - Windows 10, 日食 - 火星

/* 使用的罐子: jersey-bundle-1.9.jar (https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle/1.9) javax.ws.rs-api-2.0-m02.jar (https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api/2.0-m02) */

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.Base64;
public class JiraData {
static ClientResponse response;

public static void main(String[] args) {


try
{

String auth = new String(Base64.encode("username" + ":" + "password"));
final String headerAuthorization = "Authorization";
final String headerAuthorizationValue = "Basic " + auth;
final String headerType = "application/json";
Client c = Client.create();


WebResource webResource = c.resource("https://jira.com");
response = webResource.header(headerAuthorization, headerAuthorizationValue).type(headerType).accept(headerType).get(ClientResponse.class);
String connectionresult = response.toString();
System.out.println(connectionresult); // returned a response status of 200 OK

if (response.getResponseStatus() != null && response.getResponseStatus().getStatusCode() == 200)
{
System.out.println("Connection Successful");
fetchFields();
}


}

catch(Exception e)
{
System.out.println(" Connection Error " + e);
}




}

private static void fetchFields() {

try
{

String jql = "project = SAMPLE";
/*
* Missing logic to Capture Jira fields like Ticket Number, Ticket URL, Issue Type, Ticket Status for project passed in jql
*/


}

catch(Exception e)
{
System.out.println(" Error from fetchFields method " + e);
}

finally
{
response.close();

}


}

}

【问题讨论】:

    标签: java jira-rest-api


    【解决方案1】:

    由于您似乎想要使用 /search 端点(因为您准备了 JQL 语句),您可以使用查询参数来确定应返回哪些字段。只需使用像 /search?fields=issuekey,summary,description 这样的 URL 来定义要返回的字段列表(不要忘记也定义您的 JQL)。可以使用/field 端点访问可用字段的完整列表,请参阅REST API docs here。您还可以在REST API docs 中找到更多/search 端点的查询参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多