当前位置: 首页 > 知识库问答 >
问题:

使用JIRA REST客户端api访问JIRA敏捷冲刺

司国源
2023-03-14

有人知道如何使用JIRA java REST客户端api或其他方式使用java访问JIRA Agile Sprint吗。

1)我试图检索JIRA数据(项目、冲刺、问题等)。我需要一种方法来查询项目,冲刺以及不同的过滤器。我想JRJC无法获得敏捷数据。有没有针对整个JIRA数据的一站式服务解决方案?

2) JIRA在他们的文档中给出了两种类型的api:REST api和Java api。什么时候使用它们

共有2个答案

帅博远
2023-03-14

试试这个...我用下面的代码,

    private int setSprint(String sprint, String key, String boardId) {
    String _jiraUser = applicationProperties.get(Constants.JIRAUSER);
    String _jiraPwd = applicationProperties.get(Constants.JIRAPWD);
    String auth = new String(Base64.encode(_jiraUser + ":" + _jiraPwd));

    String agileURL = applicationProperties.get(Constants.JIRAURL)
            + "/rest/agile/1.0/board/" + boardId + "/sprint";

    int sprintId = invokeGetMethod(auth, agileURL, sprint);
    // Constants.REPORT.info(sprintId);

    String issueURL = applicationProperties.get(Constants.JIRAURL)
            + "/rest/agile/1.0/issue/" + key;

    int issueId = getIssueId(auth, issueURL, key);
    // Constants.REPORT.info(issueId);
    return invokePostMethod(auth, sprintId, key, issueId);
    // Constants.REPORT.info(statusCode);

}

private static int invokeGetMethod(String auth, String agileURL,
        String sprint) {

    int sprintId = 0;
    int startAt = 0;
    agileURL = agileURL + "?startAt=" + startAt;
    sprintId = getSprintResult(agileURL, auth, sprint, startAt);
    // sprintId = getSprintId(content, sprint, agileURL);

    return sprintId;
}

private static int getSprintResult(String agileURL, String auth,
        String sprint, int startAt) {
    HttpGet post = new HttpGet(agileURL);
    org.apache.http.impl.client.DefaultHttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient();
    post.setHeader("Content-type", "application/json");
    post.setHeader("Authorization", "Basic " + auth);
    HttpResponse response = null;
    String content = null;
    try {
        response = httpClient.execute(post);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        content = CharStreams.toString(new InputStreamReader(response
                .getEntity().getContent(), Charsets.UTF_8));
    } catch (IllegalStateException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    int SprintId = getSprintId(content, sprint, agileURL, startAt, auth);
    if (SprintId != 0)
        return SprintId;
    return SprintId;
}

static int getSprintId(String content, String sprint, String agileURL,
        int startAt, String auth) {
    boolean flag = false;

    int sprintId = 0;
    Gson gson = new Gson(); // Class<String> data=new Class<String>();
    Data values = gson.fromJson(content, Data.class);
    for (Values data : values.getValues()) { // data.get
        if (data.getName().equalsIgnoreCase(sprint))
        // Constants.REPORT.info(sprintId=data.getId());
        {
            flag = true;
            // Constants.REPORT.info(data);
            // statusCode = response.getEntityInputStream().;
            return sprintId = data.getId();
        }

    }
    if (!flag) {
    //Pagination
        agileURL = agileURL.replaceAll(
                "startAt=" + String.valueOf(startAt),
                "startAt=" + String.valueOf(startAt += 50));
        sprintId = getSprintResult(agileURL, auth, sprint, startAt);
        if (sprintId != 0)
            return sprintId;

    }
    return sprintId;

}

private static int getIssueId(String auth, String agileURL, String key) {

    int issueId = 0;
    try {

        org.apache.http.impl.client.DefaultHttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient();
        HttpGet post = new HttpGet(agileURL);

        post.setHeader("Content-type", "application/json");
        post.setHeader("Authorization", "Basic " + auth);
        HttpResponse response = httpClient.execute(post);
        String content = CharStreams.toString(new InputStreamReader(
                response.getEntity().getContent(), Charsets.UTF_8));

        Gson gson = new Gson(); // Class<String> data=new Class<String>();

        IssueData issueValues = gson.fromJson(content, IssueData.class);
        if (issueValues.getKey().equalsIgnoreCase(key))
            issueId = issueValues.getId();
        // Constants.REPORT.info(issueValues);
    } catch (Exception e) {
        Constants.ERROR.info(Level.INFO, e);
        // vjErrorLog.info(Level.INFO, e);
    }
    return issueId;
}
private static int invokePostMethod(String auth, int sprintId, String key,
        int issueId) {

    int statusCode = 0;
    try {
        String postUrl = applicationProperties.get(Constants.JIRAURL)
                + "/rest/agile/1.0/sprint/" + sprintId + "/issue";
        String str = "{\"issues\": [\"" + key + "\",\"" + issueId + "\"]}";
        statusCode = invokePostMethod(auth, postUrl, str);

        return statusCode;
    } catch (Exception e) {
        Constants.ERROR.info(Level.INFO, e);
        // vjErrorLog.info(Level.INFO, e);
    }
    return statusCode;
}

创建一个具有以下属性的IssueData类。并创建getter/setter也超过了toString()方法。

private int id;
private String self;
private String key;
白星渊
2023-03-14
  1. 你想要的所有信息都可以在这里找到:

https://docs.atlassian.com/jira/REST/latest/

请注意,您可以通过以下方式获取项目信息:https://docs.atlassian.com/jira/REST/latest/#api/2/project

a) 至于sprint信息——你能通过JQL获得你需要的信息吗?例子——你能谈谈问题吗

当你添加/删除Sprint时,你会看到URL的变化。例如,如果我选择查看Sprint 1和Sprint 6中的所有问题类型,我的JQL如下所示:

?jql=Sprint%20in%20(227%2C%20229)

请注意,这些是spint id。

现在你可以这样调用其余的api搜索:

https://jira.domain.com/rest/api/2/search?jql=Sprint%20in%20(227%2C%20229)

更多详情请点击此处:https://docs.atlassian.com/jira/REST/latest/#api/2/search

b) 如果可以通过过滤器获得所需信息,只需保存过滤器并使用rest api调用过滤器即可

https://jira.domain.com/rest/api/2/filter/{filter-id}

更多细节在这里:https://docs.atlassian.com/jira/REST/latest/#api/2/filter-getFilter

JavaAPI或Jira的RESTJava客户端是一组不受支持的库,如果您特别想使用Java来进行这些rest调用,您可以使用它。当然,您可以使用泽西或其他任何您想进行的Rest调用,但是Java客户端提供了一些可能有用的库。

 类似资料:
  • 主要内容:什么不需要敏捷?,什么是敏捷?,什么是价值?,敏捷原则敏捷是一种时间盒式的迭代方法,可以逐步构建项目,而不是一次性构建项目。敏捷是一种在整个软件中促进开发和测试的连续迭代的实践。 什么不需要敏捷? 主持会议 团队每天进行10-15分钟的频繁会议,他们认为频繁的会议将是敏捷的。但是,只有以下会议才会敏捷。 需求随时变化 需求可以随时更改,那不需要敏捷。例如,客户想要添加一些新功能并希望同时更新更改,那么这将不是敏捷。 非结构化发展 假设您没有遵循任何计

  • 我们计划将主动 MQ (STOMP) 用于我们的一个项目。其中一个要求是,如果我们发现用户不合适,就将其踢出/禁止。如何通过单板技术实现这一点?有点像在 IRC 中踢球的东西。

  • 我使用的是kafka-clients-0.10.1.1(单节点单代理) auto.create.topics.enable的默认值为true。 1.我正在使用以下方式向主题发送消息: 用于消费:

  • Spotify获取播放列表文档:https://developer.Spotify.com/web-api/get-playlists-tracks/ Spotify获取客户端凭据文档:https://developer.Spotify.com/web-api/authorization-guide/ 第一个问题,是否可以使用客户机凭据流获得用户播放列表曲目?我使用这个流,因为我无法弹出一个登录框

  • 我可以使用rest客户端API创建jira问题,但我无法将screeshot/附件附加到现有的问题。如果有人能提供一个非常感谢的解决方案,那将非常有帮助。 我刚刚编写了下面的代码片段,用于将jpeg文件附加到现有的。但后来我遇到了“线程中的异常”main“ 代码片段:- 私有静态字符串addAttachment(字符串attachmentfilepath)引发URISyntaxException、

  • 我试图用身份验证详细信息建立到业务中心服务的连接,但它给了我一个错误。然而当我在邮递员上测试它时,它工作得很完美。