fix(接口测试): 缺陷管理-禅道缺陷往ms同步,图片不显示

--bug=1011584 --user=zhaoqian
1、开源版,在ms关联禅道平台,创建缺陷,添加图片,提交
2、在禅道上修改一下缺陷,回到ms同步缺陷,同步后,图片不显示了
This commit is contained in:
zhaoqian 2022-03-31 13:59:09 +08:00 committed by jianxing
parent 6d31f9cea2
commit d6ea55962c
2 changed files with 57 additions and 9 deletions

View File

@ -134,6 +134,12 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
return list;
}
/**
* 更新缺陷数据
* @param issue 待更新缺陷数据
* @param bug 平台缺陷数据
* @return
*/
public IssuesWithBLOBs getUpdateIssues(IssuesWithBLOBs issue, JSONObject bug) {
GetIssueResponse.Issue bugObj = JSONObject.parseObject(bug.toJSONString(), GetIssueResponse.Issue.class);
String description = bugObj.getSteps();
@ -155,11 +161,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
issuesMapper.updateByPrimaryKeySelective(issue);
}
issue.setTitle(bugObj.getTitle());
// 保留之前上传的图片
String images = getImages(issue.getDescription());
issue.setDescription(steps + "\n" + images);
issue.setDescription(steps);
issue.setReporter(bugObj.getOpenedBy());
issue.setPlatform(key);
try {
@ -411,9 +413,55 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
}
private String zentao2MsDescription(String ztDescription) {
// todo 图片回显
String imgRegex = "<img src.*?/>";
return ztDescription.replaceAll(imgRegex, "");
StringBuilder resultStr = new StringBuilder();
String imgRegex ="<img src.*?/>";
Pattern pattern = Pattern.compile(imgRegex);
Matcher matcher = pattern.matcher(ztDescription);
while (matcher.find()) {
if (StringUtils.isNotEmpty(matcher.group())) {
// img标签内容
String imgPath = matcher.group();
// 解析标签内容为图片超链接格式进行替换
String src = getMatcherResultForImg("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)", imgPath);
String alt = getMatcherResultForImg("alt\\s*=\\s*\"?(.*?)(\"|>|\\s+)", imgPath);
String hyperLinkPath = packageDescriptionByPathAndName(src, alt);
imgPath = imgPath.replace("{", "\\{").replace("}", "\\}");
ztDescription = ztDescription.replaceAll(imgPath, hyperLinkPath);
}
}
return ztDescription;
}
private String packageDescriptionByPathAndName(String path, String name) {
String result = "";
if (StringUtils.isNotEmpty(path)) {
if (path.startsWith("{") && path.endsWith("}")) {
String srcContent = path.substring(1, path.length() - 1);
if (StringUtils.isEmpty(name)) {
name = srcContent;
}
path = zentaoClient.getBaseUrl() + "/file-read-" + srcContent;
}
// 图片与描述信息之间需换行否则无法预览图片
result = "\n\n![" + name + "](" + path + ")";
}
return result;
}
private String getMatcherResultForImg(String regex, String targetStr) {
String result = "";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(targetStr);
while (matcher.find()) {
result = matcher.group(1);
}
return result;
}
@Override

View File

@ -160,7 +160,7 @@ public abstract class ZentaoClient extends BaseClient {
return JSONObject.parseObject(response.getBody()).getJSONObject("data").getJSONArray("bugs");
}
protected String getBaseUrl() {
public String getBaseUrl() {
if (ENDPOINT.endsWith("/")) {
return ENDPOINT.substring(0, ENDPOINT.length() - 1);
}