From 622067d8d8aec55217785df6349f743beba36334 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 20 Jan 2022 21:29:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8B=BE=E9=80=89=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E6=A8=A1=E6=9D=BF=E6=8A=A5=E5=91=8A=E4=BA=BA=E9=80=89?= =?UTF-8?q?=E4=B8=8D=E4=B8=8A=20--bug=3D1009269=20--user=3D=E9=99=88?= =?UTF-8?q?=E5=BB=BA=E6=98=9F=20[=20github#8862]=E5=AF=B9=E6=8E=A5jira?= =?UTF-8?q?=E5=A1=AB=E5=AE=8C=E4=BA=86=E4=BD=86=E6=98=AF=E6=8A=A5=E2=80=9C?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E4=BA=BA=E4=B8=8D=E8=83=BD=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E2=80=9D=20https://www.tapd.cn/55049933/s/1091095003?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/track/issue/JiraPlatform.java | 57 ++++++++++--------- .../track/issue/domain/jira/JiraUser.java | 2 +- 2 files changed, 32 insertions(+), 27 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 9193be428c..b6581b37ce 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -177,37 +177,42 @@ public class JiraPlatform extends AbstractIssuePlatform { private void setSpecialParam(JSONObject fields) { String projectKey = getProjectId(this.projectId); JiraConfig config = getConfig(); - Map createMetadata = new HashMap<>(); try { - createMetadata = jiraClientV2.getCreateMetadata(projectKey, config.getIssuetype()); - } catch (Exception e) {} + Map createMetadata = jiraClientV2.getCreateMetadata(projectKey, config.getIssuetype()); + List userOptions = jiraClientV2.getAssignableUser(projectKey); - for (String name : createMetadata.keySet()) { - JiraCreateMetadataResponse.Field item = createMetadata.get(name); - JiraCreateMetadataResponse.Schema schema = item.getSchema(); - String key = item.getKey(); - if (StringUtils.isBlank(key)) { - continue; + Boolean isUserKey = false; + if (CollectionUtils.isNotEmpty(userOptions) && StringUtils.isBlank(userOptions.get(0).getAccountId())) { + isUserKey = true; } - if (schema != null && schema.getCustom() != null && schema.getCustom().endsWith("sprint")) { - try { + + for (String name : createMetadata.keySet()) { + JiraCreateMetadataResponse.Field item = createMetadata.get(name); + JiraCreateMetadataResponse.Schema schema = item.getSchema(); + String key = item.getKey(); + if (StringUtils.isBlank(key) || schema == null) { + continue; + } + if (schema.getCustom() != null && schema.getCustom().endsWith("sprint")) { + try { + JSONObject field = fields.getJSONObject(key); + // sprint 传参数比较特殊,需要要传数值 + fields.put(key, field.getInteger("id")); + } catch (Exception e) {} + } + if (schema.getType() != null && schema.getType().endsWith("user")) { JSONObject field = fields.getJSONObject(key); - // sprint 传参数比较特殊,需要要传数值 - fields.put(key, field.getInteger("id")); - } catch (Exception e) {} - } - if (key.equals("reporter")) { - JSONObject field = fields.getJSONObject(key); - try { - UUID.fromString(field.getString("id")); - } catch (Exception e) { - // 如果不是uuid,则是用户的key,参数调整为key - JSONObject newField = new JSONObject(); - newField.put("key", field.getString("id")); - fields.put(key, newField); + if (isUserKey) { + LogUtil.info("jira user field: " + field.toString()); + // 如果不是用户ID,则是用户的name,参数调整为name + JSONObject newField = new JSONObject(); + newField.put("name", field.getString("id")); + fields.put(key, newField); + } } } - + } catch (Exception e) { + LogUtil.error(e); } } @@ -574,7 +579,7 @@ public class JiraPlatform extends AbstractIssuePlatform { if (StringUtils.isNotBlank(val.getAccountId())) { jsonObject.put("value", val.getAccountId()); } else { - jsonObject.put("value", val.getKey()); + jsonObject.put("value", val.getName()); } jsonObject.put("text", val.getDisplayName()); options.add(jsonObject); diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/jira/JiraUser.java b/backend/src/main/java/io/metersphere/track/issue/domain/jira/JiraUser.java index bf9e68e450..ec30c025d5 100644 --- a/backend/src/main/java/io/metersphere/track/issue/domain/jira/JiraUser.java +++ b/backend/src/main/java/io/metersphere/track/issue/domain/jira/JiraUser.java @@ -7,7 +7,7 @@ import lombok.Setter; @Getter public class JiraUser { private String accountId; - private String key; + private String name; private String displayName; private String emailAddress; private Boolean active;