fix: jira 提交文本自定义字段报错 (#4312)

Co-authored-by: chenjianxing <jianxing.chen@fit2cloud.com>
This commit is contained in:
metersphere-bot 2021-07-02 11:15:28 +08:00 committed by GitHub
parent 02021c9476
commit 859006e992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 24 deletions

View File

@ -7,5 +7,6 @@ public class CustomFieldItemDTO {
private String id;
private String name;
private String value;
private String type;
private String customData;
}

View File

@ -27,6 +27,9 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.safety.Whitelist;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.CollectionUtils;
@ -208,6 +211,21 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
return new ArrayList<>();
}
/**
* 将html格式的缺陷描述转成ms平台的格式
* @param htmlDesc
* @return
*/
protected String htmlDesc2MsDesc(String htmlDesc) {
Document document = Jsoup.parse(htmlDesc);
document.outputSettings(new Document.OutputSettings().prettyPrint(false));
document.select("br").append("\\n");
document.select("p").prepend("\\n\\n");
String s = document.html().replaceAll("\\\\n", "\n");
String desc = Jsoup.clean(s, "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
return desc.replace("&nbsp;", "");
}
protected UserDTO.PlatformInfo getUserPlatInfo(String orgId) {
return userService.getCurrentPlatformInfo(orgId);
}

View File

@ -24,9 +24,6 @@ import org.apache.commons.lang3.StringUtils;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.safety.Whitelist;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@ -215,20 +212,17 @@ public class JiraPlatform extends AbstractIssuePlatform {
List<CustomFieldItemDTO> customFields = getCustomFields(issuesRequest.getCustomFields());
jiraClientV2.setConfig(config);
// List<JiraField> jiraFields = JiraClientV2.getFields();
// Map<String, Boolean> isCustomMap = jiraFields.stream().
// collect(Collectors.toMap(JiraField::getId, JiraField::isCustom));
customFields.forEach(item -> {
if (StringUtils.isNotBlank(item.getCustomData())) {
// if (isCustomMap.get(item.getCustomData())) {
// fields.put(item.getCustomData(), item.getValue());
// } else {
// Jira文档说明中自定义字段和系统字段参数格式有区别实测是一样的
if (StringUtils.isNotBlank(item.getType()) &&
StringUtils.equalsAny(item.getType(), "select", "multipleSelect", "checkbox", "radio", "member", "multipleMember")) {
JSONObject param = new JSONObject();
param.put("id", item.getValue());
fields.put(item.getCustomData(), param);
// }
} else {
fields.put(item.getCustomData(), item.getValue());
}
}
});
JiraAddIssueResponse result = jiraClientV2.addIssue(JSONObject.toJSONString(addJiraIssueParam));
@ -255,16 +249,6 @@ public class JiraPlatform extends AbstractIssuePlatform {
public void deleteIssue(String id) {
}
private String jiraDescription2Ms(String jiraDescription) {
Document document = Jsoup.parse(jiraDescription);
document.outputSettings(new Document.OutputSettings().prettyPrint(false));
document.select("br").append("\\n");
document.select("p").prepend("\\n\\n");
String s = document.html().replaceAll("\\\\n", "\n");
String desc = Jsoup.clean(s, "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
return desc.replace("&nbsp;", "");
}
@Override
public void testAuth() {
setConfig();
@ -293,7 +277,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
setConfig();
try {
parseIssue(item, jiraClientV2.getIssues(item.getId()));
item.setDescription(jiraDescription2Ms(item.getDescription()));
item.setDescription(htmlDesc2MsDesc(item.getDescription()));
issuesMapper.updateByPrimaryKeySelective(item);
} catch (HttpClientErrorException e) {
if (e.getRawStatusCode() == 404) {

View File

@ -109,7 +109,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
paramMap.add("title", issuesRequest.getTitle());
paramMap.add("workspace_id", tapdId);
paramMap.add("description", issuesRequest.getDescription());
paramMap.add("description", msDescription2Tapd(issuesRequest.getDescription()));
paramMap.add("current_owner", usersStr);
customFields.forEach(item -> {
@ -139,6 +139,10 @@ public class TapdPlatform extends AbstractIssuePlatform {
handleIssueUpdate(request);
}
private String msDescription2Tapd(String msDescription) {
return msDescription.replaceAll("\\n", "<br/>");
}
@Override
public void deleteIssue(String id) {}
@ -212,6 +216,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
IssuesDao issuesDao = new IssuesDao();
BeanUtils.copyBean(issuesDao, bug);
issuesDao.setPlatformStatus(statusMap.get(bug.getStatus()));
issuesDao.setDescription(htmlDesc2MsDesc(issuesDao.getDescription()));
issuesMapper.updateByPrimaryKeySelective(issuesDao);
ids.remove(issue.getBug().getId());
});

View File

@ -20,4 +20,4 @@ ALTER TABLE issues ADD platform_status varchar(50) NULL COMMENT '第三方平台
-- 定时同步缺陷
INSERT INTO metersphere.schedule (id,`key`,`type`,value,`group`,job,enable,resource_id,user_id,workspace_id,create_time,update_time,project_id,name)
VALUES ('7a23d4db-9909-438d-9e36-58e432c8c4ae','ISSUE_SYNC','CRON','0 0 3 * * ? ','ISSUE_SYNC','io.metersphere.job.sechedule.IssueSyncJob',1,'system','admin','system',unix_timestamp() * 1000,unix_timestamp() * 1000,'system','ISSUE_SYNC');
VALUES ('7a23d4db-9909-438d-9e36-58e432c8c4ae','ISSUE_SYNC','CRON','0 0 3 * * ?','ISSUE_SYNC','io.metersphere.job.sechedule.IssueSyncJob',1,'system','admin','system',unix_timestamp() * 1000,unix_timestamp() * 1000,'system','ISSUE_SYNC');

View File

@ -114,6 +114,7 @@ export function buildCustomFields(data, param, template) {
id: item.id,
name: item.name,
value: item.defaultValue,
type: item.type,
customData: item.customData,
};
customFields.push(customField);