fix: 禅道path_info方式同步缺陷报错

【缺陷双向同步功能,在请求方式默认为PATH_INFO时,无法同步禅道的缺陷至MS,同步报错,请修改】https://www.tapd.cn/33805590/bugtrace/bugs/view?bug_id=11338055900010086377
This commit is contained in:
chenjianxing 2021-12-21 17:07:58 +08:00 committed by john1298308460
parent eb80bb6f1e
commit c66473b16f
9 changed files with 22 additions and 5 deletions

View File

@ -140,7 +140,11 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
issuesMapper.updateByPrimaryKeySelective(issue);
}
issue.setTitle(bugObj.getTitle());
issue.setDescription(steps);
// 保留之前上传的图片
String images = getImages(issue.getDescription());
issue.setDescription(steps + "\n" + images);
issue.setReporter(bugObj.getOpenedBy());
issue.setPlatform(key);
try {

View File

@ -1,9 +1,11 @@
package io.metersphere.track.issue.client;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.i18n.Translator;
import io.metersphere.track.issue.domain.zentao.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpEntity;
@ -29,9 +31,6 @@ public abstract class ZentaoClient extends BaseClient {
ENDPOINT = url;
}
// 注意 recTotal={1}&recPerPage={2}&pageID={3} 顺序不能调换实在恶心
private static final String BUG_LIST_URL = "?m=bug&f=browse&productID={0}&branch=&browseType=&param=0&orderBy=&recTotal={1}&recPerPage={2}&pageID={3}&t=json&zentaosid={4}";
public String login() {
GetUserResponse getUserResponse = new GetUserResponse();
String sessionId = "";
@ -46,6 +45,8 @@ public abstract class ZentaoClient extends BaseClient {
getUserResponse = (GetUserResponse) getResultForObject(GetUserResponse.class, response);
} catch (Exception e) {
LogUtil.error(e);
if (e instanceof JSONException)
MSException.throwException(Translator.get("zentao_test_type_error"));
MSException.throwException(e.getMessage());
}
GetUserResponse.User user = getUserResponse.getUser();
@ -121,7 +122,7 @@ public abstract class ZentaoClient extends BaseClient {
public JSONArray getBugsByProjectId(String projectId, int pageNum, int pageSize) {
String sessionId = login();
ResponseEntity<String> response = restTemplate.exchange(getBaseUrl() + BUG_LIST_URL,
ResponseEntity<String> response = restTemplate.exchange(requestUrl.getBugList(),
HttpMethod.GET, null, String.class, projectId, 9999999, pageSize, pageNum, sessionId);
return JSONObject.parseObject(response.getBody()).getJSONObject("data").getJSONArray("bugs");
}

View File

@ -18,6 +18,8 @@ public class ZentaoGetClient extends ZentaoClient {
private static final String FILE_UPLOAD="&module=file&methodName=saveUpload&t=json&zentaosid=";
private static final String REPLACE_IMG_URL="<img src=\"%s/index.php?m=file&f=read&fileID=$1\"/>";
private static final Pattern IMG_PATTERN = Pattern.compile("m=file&f=read&fileID=(.*?)\"/>");
// 注意 recTotal={1}&recPerPage={2}&pageID={3} 顺序不能调换有点恶心
private static final String BUG_LIST_URL = "/?m=bug&f=browse&productID={0}&branch=&browseType=&param=0&orderBy=&recTotal={1}&recPerPage={2}&pageID={3}&t=json&zentaosid={4}";
RequestUrl request = new RequestUrl();
@ -38,6 +40,7 @@ public class ZentaoGetClient extends ZentaoClient {
request.setImgPattern(IMG_PATTERN);
request.setBugUpdate(getUrl(BUG_UPDATE));
request.setBugDelete(getNotSuperModelUrl(BUG_DELETE));
request.setBugList(getNotSuperModelUrl(BUG_LIST_URL));
requestUrl = request;
}

View File

@ -19,6 +19,8 @@ public class ZentaoPathInfoClient extends ZentaoClient {
private static final String FILE_UPLOAD = "/api-getModel-file-saveUpload.json?zentaosid=";
private static final String REPLACE_IMG_URL = "<img src=\"%s/file-read-$1\"/>";
private static final Pattern IMG_PATTERN = Pattern.compile("file-read-(.*?)\"/>");
private static final String BUG_LIST_URL = "/bug-browse-{1}---0--{2}-{3}-{4}.json?zentaosid={5}";
public ZentaoPathInfoClient(String url) {
super(url);
@ -39,6 +41,7 @@ public class ZentaoPathInfoClient extends ZentaoClient {
request.setImgPattern(IMG_PATTERN);
request.setBugUpdate(getUrl(BUG_UPDATE));
request.setBugDelete(getUrl(BUG_DELETE));
request.setBugList(getUrl(BUG_LIST_URL));
requestUrl = request;
}

View File

@ -12,6 +12,7 @@ public class RequestUrl {
private String sessionGet;
private String bugCreate;
private String bugUpdate;
private String bugList;
private String bugDelete;
private String bugGet;
private String storyGet;

View File

@ -71,3 +71,5 @@ expect_name_exists=
id_not_rightful=
mock_warning=
invalid_parameter=
workspace_template_settings_issue=
zentao_test_type_error=

View File

@ -285,5 +285,6 @@ test_case_status=Case status
id_not_rightful=ID is not rightful
# mock
mock_warning=No matching Mock expectation was found
zentao_test_type_error=请求方式错误
#项目报告
enterprise_test_report=Enterprise report

View File

@ -284,5 +284,6 @@ test_case_status=用例状态
id_not_rightful=ID 不合法
# mock
mock_warning=未找到匹配的Mock期望
zentao_test_type_error=invalid Zentao request
#项目报告
enterprise_test_report=项目报告

View File

@ -284,5 +284,6 @@ test_case_status=用例狀態
id_not_rightful=ID 不合法
# mock
mock_warning=未找到匹配的Mock期望
zentao_test_type_error=請求方式錯誤
#项目报告
enterprise_test_report=項目報告