如何通过Java检索JIRA rest api附件列表?

白猫

如何使用带有Java的JIRA API获得附件列表?我不需要附件,我只想知道那里的附件及其ID。我遵循了使用查询来获取问题的基础知识,但遇到的却是问题,但没有附件。我的代码:

[String searchQuery = "(created >= '2015/12/1' ) AND (created < '2016/01/1')" 
JiraAuthentication jiraAuth;
JiraRestClient arc;
// Get JiraAuthentication instance to create basic HTTP authentication
// string
jiraAuth = JiraAuthentication.getInstance();

// Make sure you use a new instance
jiraAuth.initInstance();
jiraAuth = JiraAuthentication.getInstance();

// Get the JIRA Rest Client from the basic HTTP authentication
jrc = jiraAuth.getJrc();

// Receive search results based on query
SearchRestClient searchClient = jrc.getSearchClient();
// limit results to 50
SearchResult result = searchClient.searchJql(searchQuery, 50,0, null);
Iterator<BasicIssue> itIssue = result.getIssues().iterator();

// pull information on individual issues.
while (itIssue.hasNext()) {
   BasicIssue lBasicIssue = (BasicIssue) itIssue.next();
   String lIssueKey = lBasicIssue.getKey();
   Issue issue = jrc.getIssueClient().getIssue(lIssueKey, null);
   //This line should print the list of attachments. but everything is always null.
   System.out.println(issue.getAttachements());
}][1]

我尝试获取信息的一个示例是HBASE-15062,它具有api链接在api链接中没有显示任何附件,但在实际链接中有4个附件。

我知道Jira api调用api/2/issue/{issueIdOrKey}/attachments

我尝试了:api / 2 / issue / 12925031 / attachments我得到了响应HTTP Status 405 - Method Not Allowed这是否意味着我无法获得附件列表,或者我只是在做错请求?

如何更改我的Java代码以获取附件?是否可以从APACHE JIRA获得附件?

白猫

我想说简尼斯答案将我引向这个问题的答案。

添加参数的jannis方法?expand=changelog是获取附件的唯一方法。getIssue()需要更改的Java调用我在这里找到了如何添加参数,api信息在这里

getIssue(String issueKey, ProgressMonitor progressMonitor) 使用:

Issue issue = jrc.getIssueClient().getIssue(lIssueKey, null);

Issue getIssue(String issueKey, Iterable<IssueRestClient.Expandos> expand, ProgressMonitor progressMonitor) 应该使用:

   Issue issue = jrc.getIssueClient().getIssue(lIssueKey, Arrays.asList(IssueRestClient.Expandos.CHANGELOG), null);

随着对getIssue的更改调用,应该填充changelog字段。然后,您可以通过迭代更改日志来使用此字段来查看附件。我这样做:

private null findAttachments(Issue issue) {
    String FieldName = "Attachment";
    Iterable<ChangelogGroup> changes = issue.getChangelog();
    StringBuilder attachments = new StringBuilder();
    StringBuilder attachmentsIDs = new StringBuilder();

    for (ChangelogGroup change: changes){
        //Multiple change items per group. 
        for(ChangelogItem item: change.getItems()){
            if(item.getField().equals(FieldName)){
                //Gets attachment name.
                attachments.append((String) item.getToString());
                //Gets attachment ID to download if needed.
                attachmentsIDs.append((String) item.getTo());
            }
        }
    }
    //Do something with attachments here..

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何通过REST API检索JIRA票证的摘要?

查询包含空格时如何通过REST API检索Jira问题

如何从Office 365 REST API检索ItemAttachment的附件?

如何使用REST API从附件读取媒体

使用Jira 6.4.3将附件发布到Rest api

如何通过REST API查找JIRA问题的状态?

Docusign REST API附件

Azure Devops:如何通过 Rest API 检索发布工件的版本?

如何通过REST API检索页面上的图像URL

从TFS REST API检索代理请求列表

JIRA-Java API或REST API

Jira REST API Java - 缺少工件

如何正确调用Jira Rest API

通过rest API检索交易ID

如何通过 jira rest api 从特定的未发布版本中获取所有问题

如何通过REST API更新JIRA中的自定义字段?

如何通过REST API向JIRA发送POST请求以创建项目

Jira——如何通过 REST API 获取问题变更日志——但不是单一问题

如何通过 REST API 在 jira 票证中获取集成版本字段?

如何通过 REST API 获取 JIRA 问题的描述、受让人名称?

Outlook 365 Mail Rest API:检索.eml附件时收到内部服务器错误

如何使用图谱API获取SharePoint Online列表项附件?

如何通过 DevOps REST API 获取特定提交的构建列表

如何正确迭代通过React JS中通过Wp Rest Api检索的发布对象数组

如何使用REST API删除项目列表

OTRS - REST-API - 通过 SMTPLIB 发送包括附件在内的票证内容

通过 PowerShell 使用 REST API 创建 JIRA 问题

Jira V6.0 +通过REST API创建项目

无法通过rest api将测试结果导入jira