From 51acb89783062a53591a9c9ac5ae5961fb48e20b Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Sun, 5 Jun 2022 16:28:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=90=8C=E6=AD=A5jira=E5=9B=BE=E7=89=87=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1013769 --user=陈建星 【测试跟踪】github#13768,项目MS创建缺陷中含有图片-点击同步缺陷到JIRA-MS缺陷中的图片消失-JIRA中的图片还在 https://www.tapd.cn/55049933/s/1172335 --- .../io/metersphere/track/issue/JiraPlatform.java | 13 +++++++++---- .../track/issue/client/JiraAbstractClient.java | 14 +++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) 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 a3d2f671ba..7f3c30e380 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -75,6 +75,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")); @@ -100,7 +101,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 { @@ -117,6 +118,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附件:")) { // 解析标签内容 @@ -130,6 +132,10 @@ public class JiraPlatform extends AbstractIssuePlatform { } } + for (String key: fileContentMap.keySet()) { + // 同步jira上传的附件 + description += "\n" + fileContentMap.get(key); + } return description; } @@ -215,15 +221,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();