From 2292cf08b0a7aec3e0570fda6a7dfce1338bcd5e Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 25 Jan 2022 12:14:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20jira=E5=8B=BE=E9=80=89=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E5=9B=BE=E7=89=87=E6=98=BE=E7=A4=BA=20--bug?= =?UTF-8?q?=3D1009500=20--user=3D=E9=99=88=E5=BB=BA=E6=98=9F=20=E3=80=90gi?= =?UTF-8?q?thub#9176=E3=80=91=E3=80=90=E5=AF=B9=E6=8E=A5jira=E3=80=91?= =?UTF-8?q?=E5=88=9B=E5=BB=BAjira=E7=BC=BA=E9=99=B7=E6=97=B6=EF=BC=8Cms?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=87=8C=E9=9D=A2=E7=9A=84=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=B2=98=E8=B4=B4=E5=9B=BE=E7=89=87=EF=BC=8C?= =?UTF-8?q?=E4=BD=86jira=E7=B3=BB=E7=BB=9F=E6=B2=A1=E6=9C=89=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=9B=BE=E7=89=87=E5=87=BA=E6=9D=A5=20https://www.tap?= =?UTF-8?q?d.cn/55049933/s/10979000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/issue/AbstractIssuePlatform.java | 7 ++++- .../metersphere/track/issue/JiraPlatform.java | 27 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java b/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java index cc19912f8f..dee9e31498 100644 --- a/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java @@ -498,7 +498,12 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { Set ids = issueFields.stream().map(i -> ((JSONObject) i).getString("id")).collect(Collectors.toSet()); JSONArray defaultFields = JSONArray.parseArray(defaultCustomField); defaultFields.forEach(item -> { // 如果自定义字段里没有模板新加的字段,就把新字段加上 - if (!ids.contains(((JSONObject) item).getString("id"))) { + String id = ((JSONObject) item).getString("id"); + if (StringUtils.isBlank(id)) { + id = ((JSONObject) item).getString("key"); + ((JSONObject) item).put("id", id); + } + if (!ids.contains(id)) { issueFields.add(item); } }); 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 7b3c98b5a0..756d680852 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -141,12 +141,12 @@ public class JiraPlatform extends AbstractIssuePlatform { setUserConfig(); Project project = getProject(); + List imageFiles = getImageFiles(issuesRequest); JSONObject addJiraIssueParam = buildUpdateParam(issuesRequest, getIssueType(project.getIssueConfig()), project.getJiraKey()); + JiraAddIssueResponse result = jiraClientV2.addIssue(JSONObject.toJSONString(addJiraIssueParam)); JiraIssue issues = jiraClientV2.getIssues(result.getId()); - List imageFiles = getImageFiles(issuesRequest.getDescription()); - imageFiles.forEach(img -> jiraClientV2.uploadAttachment(result.getKey(), img)); String status = getStatus(issues.getFields()); @@ -168,6 +168,24 @@ public class JiraPlatform extends AbstractIssuePlatform { return super.getProject(this.projectId, Project::getJiraKey); } + private List getImageFiles(IssuesUpdateRequest issuesRequest) { + List files = getImageFiles(issuesRequest.getDescription()); + 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")) { + files.addAll(getImageFiles(item.getValue().toString())); + } + } + } + } + }); + return files; + } + /** * 参数比较特殊,需要特别处理 * @param fields @@ -294,6 +312,11 @@ public class JiraPlatform extends AbstractIssuePlatform { } fields.put(fieldName, attr); } + } else if (StringUtils.equalsAny(item.getType(), "richText")) { + fields.put(fieldName, removeImage(item.getValue().toString())); + if (fieldName.equals("description")) { + issuesRequest.setDescription(item.getValue().toString()); + } } else { fields.put(fieldName, item.getValue()); }