diff --git a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java index 680f8e501c..d23e868e00 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -74,6 +74,7 @@ public class JiraPlatform extends AbstractIssuePlatform { String status = getStatus(fields); String description = dealWithDescription(fields.getString("description"), fields.getJSONArray("attachment")); + fields.put("description", description); JSONObject assignee = (JSONObject) fields.get("assignee"); issue.setTitle(fields.getString("summary")); @@ -99,7 +100,7 @@ public class JiraPlatform extends AbstractIssuePlatform { JSONObject attachment = attachments.getJSONObject(i); String filename = attachment.getString("filename"); String content = attachment.getString("content"); - if (StringUtils.equals(attachment.getString("mimeType"), "image/jpeg")) { + if (StringUtils.contains(attachment.getString("mimeType"), "image")) { String contentUrl = "![" + filename + "](" + content + ")"; fileContentMap.put(filename, contentUrl); } else { @@ -116,6 +117,7 @@ public class JiraPlatform extends AbstractIssuePlatform { List keys = fileContentMap.keySet().stream().filter(key -> splitStr.contains(key)).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(keys)) { description = description.replace(splitStr, fileContentMap.get(keys.get(0))); + fileContentMap.remove(keys.get(0)); } else { if (splitStr.contains("MS附件:")) { // 解析标签内容 @@ -129,6 +131,10 @@ public class JiraPlatform extends AbstractIssuePlatform { } } + for (String key: fileContentMap.keySet()) { + // 同步jira上传的附件 + description += "\n" + fileContentMap.get(key); + } return description; } @@ -214,15 +220,14 @@ public class JiraPlatform extends AbstractIssuePlatform { } private List getImageFiles(IssuesUpdateRequest issuesRequest) { - List files = getImageFiles(issuesRequest.getDescription()); + List files = new ArrayList<>(); List customFields = CustomFieldService.getCustomFields(issuesRequest.getCustomFields()); customFields.forEach(item -> { String fieldName = item.getCustomData(); if (StringUtils.isNotBlank(fieldName)) { if (item.getValue() != null) { if (StringUtils.isNotBlank(item.getType())) { - if (StringUtils.equalsAny(item.getType(), "richText") - && !item.getId().equals("description")) { + if (StringUtils.equalsAny(item.getType(), "richText")) { files.addAll(getImageFiles(item.getValue().toString())); } } diff --git a/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java b/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java index 1450bad7a5..6ee996cef7 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java @@ -243,12 +243,24 @@ public abstract class JiraAbstractClient extends BaseClient { } public JiraIssueListResponse getProjectIssues(int startAt, int maxResults, String projectKey, String issueType) { + return getProjectIssues(startAt, maxResults, projectKey, issueType, null); + } + + public JiraIssueListResponse getProjectIssues(int startAt, int maxResults, String projectKey, String issueType, String fields) { ResponseEntity responseEntity; - responseEntity = restTemplate.exchange(getBaseUrl() + "/search?startAt={1}&maxResults={2}&jql=project={3}+AND+issuetype={4}", + String url = getBaseUrl() + "/search?startAt={1}&maxResults={2}&jql=project={3}+AND+issuetype={4}"; + if (StringUtils.isNotBlank(fields)) { + url = url + "&fields=" + fields; + } + responseEntity = restTemplate.exchange(url, HttpMethod.GET, getAuthHttpEntity(), String.class, startAt, maxResults, projectKey, issueType); return (JiraIssueListResponse)getResultForObject(JiraIssueListResponse.class, responseEntity); } + public JiraIssueListResponse getProjectIssuesAttachment(int startAt, int maxResults, String projectKey, String issueType) { + return getProjectIssues(startAt, maxResults, projectKey, issueType, "attachment"); + + } public void setTransitions(String jiraKey, JiraTransitionsResponse.Transitions transitions) { LogUtil.info("setTransitions: " + transitions); JSONObject jsonObject = new JSONObject();