Jira rest api,添加带有转换的附件

Jira rest api,添加带有转换的附件,jira,jira-rest-api,Jira,Jira Rest Api,在jirarestapi中,我们正在使用转换api。 通过使用转换id和注释以及其他字段在/rest/api/2/issue/{issueidworkey}/transitions url上发布,我们可以使用状态转换发布注释和其他字段 { "fields" : {"summary": "Test update 5"}, "transition": { "id": "4"}, "update": { "comment": [ {

在jirarestapi中,我们正在使用转换api。 通过使用转换id和注释以及其他字段在/rest/api/2/issue/{issueidworkey}/transitions url上发布,我们可以使用状态转换发布注释和其他字段

{
    "fields" : {"summary": "Test update 5"},
    "transition": { "id": "4"},
"update": {
      "comment": [
         {
            "add": {
               "body": "It is time to finish this task"
            }
         }
      ]
   }

}
最近我们知道jira也有附件验证。意味着如果我进行转换,我需要添加附件。我们正在研究如何使用RESTAPI在转换期间添加附件

任何帮助都将不胜感激


提前谢谢

不确定它在转换期间是否有效,但下面介绍如何添加附件


我必须打两个电话——首先是创建问题,然后是另一个POST电话,用屏幕截图更新问题,因为根本无法在创建电话中添加附件。

我不确定是否要添加带有转换的附件(我从未做过),但我认为可以使用clubbed。下面是向JIRA添加附件的代码,您可以使用JRJC的转换API并在下面的代码中应用/添加一些逻辑来完成工作

跟踪链接[ 对于基于转换的状态更新,希望您也能从这里获得一些信息

public void addAttachment(IssueRestClient issueRestClient,
        VersionOne versionOne, Issue issue, Epics epic) {

    try {

        URI attachmentsUri = new URI(
                applicationProperties.get(Constants.JIRAURL)
                        + "/rest/api/2/issue/" + issue.getKey()
                        + "/attachments");
        Iterable<Attachment> attachments = issue.getAttachments();
        Set<String> existingAttachments = new TreeSet<String>();
        String _jiraUser = applicationProperties.get(Constants.JIRAUSER);
        String _jiraPwd = applicationProperties.get(Constants.JIRAPWD);
        String auth = new String(Base64.encode(_jiraUser + ":" + _jiraPwd));
        Set<String> files = new TreeSet<String>();

        for (Attachment attachment : attachments) {
            for (VAttachements vAttachement : epic
                    .getAttachement()) {
                files.add(vAttachement.getFileName());

            }
            existingAttachments.add(attachment.getFilename());
        }

        for (VAttachements vAttachement : epic.getvAttachement()) {

            if (!(existingAttachments.contains(vAttachement.getFileName()))) {

                Promise<Void> attachmentResult = issueRestClient
                        .addAttachment(attachmentsUri,
                                vAttachement.getInputStream(),
                                vAttachement.getFileName());
                attachmentResult.claim();
                Constants.REPORT.info(attachmentResult.isDone());

            }

        }
        for (Attachment attachment : attachments) {
            for (String checkAttachment : existingAttachments) {
                if (!files.contains(checkAttachment))
                    deleteJiraAttachment(attachment, auth, issue,
                            checkAttachment);

            }
        }

    } catch (Exception e) {
        Constants.ERROR.info(Level.INFO, e);

    }
}
private void deleteJiraAttachment(Attachment attachment, String auth,
        Issue issue, String jiraFilename) {

    URI attachmentURL = attachment.getSelf();

    int status;
    try {
        if (jiraFilename.equalsIgnoreCase(attachment.getFilename())) {
            status = invokeDeleteMethod(auth, String.valueOf(attachmentURL));

            if (status == 204) {
                Constants.REPORT.info("Attachment deleted from Issue"
                        + issue.getKey());
            } else if (status == 403) {
                System.out
                        .println("attachments for Issue\t "
                                + issue.getKey()
                                + " is disabled or you don't have permission to remove");
            } else if (status == 404) {
                Constants.REPORT.info("No attachment is not found for"
                        + issue.getKey());
            }
        }
    } catch (AuthenticationException | ClientHandlerException e) {
        Constants.ERROR.info(Level.INFO, e);

    }

}

private static int invokeDeleteMethod(String auth, String url)
        throws AuthenticationException, ClientHandlerException {

    Client client = Client.create();
    WebResource webResource = client.resource(url);
    ClientResponse response = webResource
            .header("Authorization", "Basic " + auth)
            .type("application/json").accept("application/json")
            .delete(ClientResponse.class);
    int statusCode = response.getStatus();
    if (statusCode == 401) {
        throw new AuthenticationException("Invalid Username or Password");
    }
    return statusCode;