fix: 同步缺陷
This commit is contained in:
parent
e36a8d9e7d
commit
f0a0410df4
|
@ -359,24 +359,18 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
|
|||
if (!fieldName.equals("assignee") && !fieldName.equals("reporter")) { // 获取不到账号名
|
||||
item.setValue(((JSONObject)value).getString("id"));
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isNotBlank(item.getType()) &&
|
||||
StringUtils.equalsAny(item.getType(), "multipleSelect", "checkbox", "multipleMember")) {
|
||||
List<String> values = new ArrayList<>();
|
||||
if (item.getValue() != null) {
|
||||
JSONArray attrs = (JSONArray) item.getValue();
|
||||
attrs.forEach(attr -> {
|
||||
if (attr instanceof JSONObject) {
|
||||
values.add(((JSONObject)attr).getString("id"));
|
||||
} else {
|
||||
values.add((String) attr);
|
||||
}
|
||||
});
|
||||
} else if (value instanceof JSONArray) {
|
||||
List<Object> values = new ArrayList<>();
|
||||
((JSONArray)value).forEach(attr -> {
|
||||
if (attr instanceof JSONObject) {
|
||||
values.add(((JSONObject)attr).getString("id"));
|
||||
} else {
|
||||
values.add(attr);
|
||||
}
|
||||
item.setValue(values);
|
||||
} else {
|
||||
item.setValue(value);
|
||||
}
|
||||
});
|
||||
item.setValue(values);
|
||||
} else {
|
||||
item.setValue(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -424,7 +418,7 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
|
|||
protected void mergeCustomField(IssuesWithBLOBs issues, String defaultCustomField) {
|
||||
if (StringUtils.isNotBlank(defaultCustomField)) {
|
||||
String issuesCustomFields = issues.getCustomFields();
|
||||
if (StringUtils.isNotBlank(issuesCustomFields) || issuesCustomFields.startsWith("{")) issuesCustomFields = "[]";
|
||||
if (StringUtils.isBlank(issuesCustomFields) || issuesCustomFields.startsWith("{")) issuesCustomFields = "[]";
|
||||
JSONArray issueFields = JSONArray.parseArray(issuesCustomFields);
|
||||
Set<String> ids = issueFields.stream().map(i -> ((JSONObject) i).getString("id")).collect(Collectors.toSet());
|
||||
JSONArray defaultFields = JSONArray.parseArray(defaultCustomField);
|
||||
|
@ -442,4 +436,15 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
|
|||
if (StringUtils.isBlank(config)) MSException.throwException("配置为空");
|
||||
return JSONObject.parseObject(config, clazz);
|
||||
}
|
||||
|
||||
public void buildSyncCreate(IssuesWithBLOBs issue, String platformId, Integer nextNum) {
|
||||
issue.setProjectId(projectId);
|
||||
issue.setId(UUID.randomUUID().toString());
|
||||
issue.setPlatformId(platformId);
|
||||
issue.setCreateTime(System.currentTimeMillis());
|
||||
issue.setUpdateTime(System.currentTimeMillis());
|
||||
issue.setCreator(SessionUtils.getUserId());
|
||||
issue.setNum(nextNum);
|
||||
issuesMapper.insert(issue); // 批量新增
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,31 @@
|
|||
package io.metersphere.track.issue;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.domain.IssuesDao;
|
||||
import io.metersphere.base.domain.IssuesWithBLOBs;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.domain.TestCaseWithBLOBs;
|
||||
import io.metersphere.commons.constants.IssuesManagePlatform;
|
||||
import io.metersphere.commons.constants.IssuesStatus;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.EncryptUtils;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.dto.CustomFieldItemDTO;
|
||||
import io.metersphere.dto.UserDTO;
|
||||
import io.metersphere.service.CustomFieldService;
|
||||
import io.metersphere.track.dto.DemandDTO;
|
||||
import io.metersphere.track.issue.client.JiraClientV2;
|
||||
import io.metersphere.track.issue.domain.PlatformUser;
|
||||
import io.metersphere.track.issue.domain.jira.JiraAddIssueResponse;
|
||||
import io.metersphere.track.issue.domain.jira.JiraConfig;
|
||||
import io.metersphere.track.issue.domain.jira.JiraIssue;
|
||||
import io.metersphere.track.issue.domain.PlatformUser;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
import io.metersphere.track.request.testcase.IssuesUpdateRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.commonmark.node.Node;
|
||||
import org.commonmark.parser.Parser;
|
||||
import org.commonmark.renderer.html.HtmlRenderer;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -102,62 +98,25 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
|||
@Override
|
||||
public List<DemandDTO> getDemandList(String projectId) {
|
||||
List<DemandDTO> list = new ArrayList<>();
|
||||
|
||||
try {
|
||||
String key = validateJiraKey(projectId);
|
||||
String config = getPlatformConfig(IssuesManagePlatform.Jira.toString());
|
||||
JSONObject object = JSON.parseObject(config);
|
||||
|
||||
if (object == null) {
|
||||
MSException.throwException("jira config is null");
|
||||
JiraConfig config = getConfig();
|
||||
int maxResults = 50, startAt = 0;
|
||||
JSONArray demands;
|
||||
String key = validateJiraKey(projectId);
|
||||
do {
|
||||
demands = jiraClientV2.getDemands(key, config.getStorytype(), startAt, maxResults);
|
||||
for (int i = 0; i < demands.size(); i++) {
|
||||
JSONObject o = demands.getJSONObject(i);
|
||||
String issueKey = o.getString("key");
|
||||
JSONObject fields = o.getJSONObject("fields");
|
||||
String summary = fields.getString("summary");
|
||||
DemandDTO demandDTO = new DemandDTO();
|
||||
demandDTO.setName(summary);
|
||||
demandDTO.setId(issueKey);
|
||||
demandDTO.setPlatform(IssuesManagePlatform.Jira.name());
|
||||
list.add(demandDTO);
|
||||
}
|
||||
|
||||
String account = object.getString("account");
|
||||
String password = object.getString("password");
|
||||
String url = object.getString("url");
|
||||
String type = object.getString("storytype");
|
||||
String auth = EncryptUtils.base64Encoding(account + ":" + password);
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.add("Authorization", "Basic " + auth);
|
||||
requestHeaders.setContentType(org.springframework.http.MediaType.APPLICATION_JSON);
|
||||
//HttpEntity
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(requestHeaders);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
//post
|
||||
ResponseEntity<String> responseEntity = null;
|
||||
int maxResults = 50, startAt = 0, total = 0, currentStartAt = 0;
|
||||
do {
|
||||
String jql = url + "/rest/api/2/search?jql=project=" + key + "+AND+issuetype=" + type
|
||||
+ "&maxResults=" + maxResults + "&startAt=" + startAt + "&fields=summary,issuetype";
|
||||
responseEntity = restTemplate.exchange(jql,
|
||||
HttpMethod.GET, requestEntity, String.class);
|
||||
String body = responseEntity.getBody();
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("issues");
|
||||
if (jsonArray.size() == 0) {
|
||||
break;
|
||||
}
|
||||
total = jsonObject.getInteger("total");
|
||||
startAt = startAt + maxResults;
|
||||
currentStartAt = jsonObject.getInteger("startAt");
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject o = jsonArray.getJSONObject(i);
|
||||
String issueKey = o.getString("key");
|
||||
JSONObject fields = o.getJSONObject("fields");
|
||||
String summary = fields.getString("summary");
|
||||
DemandDTO demandDTO = new DemandDTO();
|
||||
demandDTO.setName(summary);
|
||||
demandDTO.setId(issueKey);
|
||||
demandDTO.setPlatform(IssuesManagePlatform.Jira.name());
|
||||
list.add(demandDTO);
|
||||
}
|
||||
} while (currentStartAt + maxResults < total);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
startAt += maxResults;
|
||||
} while (demands.size() >= maxResults);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package io.metersphere.track.issue;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.base.domain.IssuesDao;
|
||||
|
@ -12,9 +11,7 @@ import io.metersphere.commons.constants.IssuesStatus;
|
|||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.ResultHolder;
|
||||
import io.metersphere.dto.UserDTO;
|
||||
import io.metersphere.service.SystemParameterService;
|
||||
import io.metersphere.track.dto.DemandDTO;
|
||||
|
@ -27,8 +24,6 @@ import io.metersphere.track.request.testcase.IssuesRequest;
|
|||
import io.metersphere.track.request.testcase.IssuesUpdateRequest;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
|
@ -65,21 +60,13 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
|||
@Override
|
||||
public List<DemandDTO> getDemandList(String projectId) {
|
||||
List<DemandDTO> demandList = new ArrayList<>();
|
||||
try {
|
||||
String url = "https://api.tapd.cn/stories?workspace_id=" + getProjectId(projectId);
|
||||
ResultHolder call = call(url);
|
||||
String listJson = JSON.toJSONString(call.getData());
|
||||
JSONArray jsonArray = JSON.parseArray(listJson);
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject o = jsonArray.getJSONObject(i);
|
||||
DemandDTO demand = o.getObject("Story", DemandDTO.class);
|
||||
demand.setPlatform(IssuesManagePlatform.Tapd.name());
|
||||
demandList.add(demand);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
JSONArray demands = tapdClient.getDemands(getProjectId(projectId));
|
||||
for (int i = 0; i < demands.size(); i++) {
|
||||
JSONObject o = demands.getJSONObject(i);
|
||||
DemandDTO demand = o.getObject("Story", DemandDTO.class);
|
||||
demand.setPlatform(IssuesManagePlatform.Tapd.name());
|
||||
demandList.add(demand);
|
||||
}
|
||||
|
||||
return demandList;
|
||||
}
|
||||
|
||||
|
@ -166,7 +153,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
|||
@Override
|
||||
public List<PlatformUser> getPlatformUser() {
|
||||
List<PlatformUser> users = new ArrayList<>();
|
||||
JSONArray res = tapdClient.getPlatformUser(projectId);
|
||||
JSONArray res = tapdClient.getPlatformUser(getProjectId(projectId));
|
||||
for (int i = 0; i < res.size(); i++) {
|
||||
JSONObject o = res.getJSONObject(i);
|
||||
PlatformUser user = o.getObject("UserWorkspace", PlatformUser.class);
|
||||
|
@ -264,40 +251,4 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ResultHolder call(String url) {
|
||||
return call(url, HttpMethod.GET, null);
|
||||
}
|
||||
|
||||
private ResultHolder call(String url, HttpMethod httpMethod, Object params) {
|
||||
String responseJson;
|
||||
|
||||
String config = getPlatformConfig(IssuesManagePlatform.Tapd.toString());
|
||||
JSONObject object = JSON.parseObject(config);
|
||||
|
||||
if (object == null) {
|
||||
MSException.throwException("tapd config is null");
|
||||
}
|
||||
|
||||
String account = object.getString("account");
|
||||
String password = object.getString("password");
|
||||
|
||||
HttpHeaders header = auth(account, password);
|
||||
|
||||
if (httpMethod.equals(HttpMethod.GET)) {
|
||||
responseJson = TapdRestUtils.get(url, header);
|
||||
} else {
|
||||
responseJson = TapdRestUtils.post(url, params, header);
|
||||
}
|
||||
|
||||
ResultHolder result = JSON.parseObject(responseJson, ResultHolder.class);
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
MSException.throwException(result.getMessage());
|
||||
}
|
||||
return JSON.parseObject(responseJson, ResultHolder.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@ import org.apache.commons.lang3.StringUtils;
|
|||
|
||||
public class ZentaoFactory {
|
||||
|
||||
public static ZentaoClient getInstance(String type) {
|
||||
public static ZentaoClient getInstance(String url, String type) {
|
||||
if (StringUtils.equals(type, "PATH_INFO")) {
|
||||
return new ZentaoPathInfoClient();
|
||||
return new ZentaoPathInfoClient(url);
|
||||
} else if (StringUtils.equals(type, "GET")) {
|
||||
return new ZentaoGetClient();
|
||||
return new ZentaoGetClient(url);
|
||||
}
|
||||
return new ZentaoPathInfoClient();
|
||||
return new ZentaoPathInfoClient(url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
|||
super(issuesRequest);
|
||||
ZentaoConfig zentaoConfig = getConfig();
|
||||
this.workspaceId = issuesRequest.getWorkspaceId();
|
||||
this.zentaoClient = ZentaoFactory.getInstance(zentaoConfig.getRequest());
|
||||
this.zentaoClient = ZentaoFactory.getInstance(zentaoConfig.getUrl(), zentaoConfig.getRequest());
|
||||
this.zentaoClient.setConfig(zentaoConfig);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package io.metersphere.track.issue.client;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.track.issue.domain.jira.JiraAddIssueResponse;
|
||||
|
@ -33,6 +35,15 @@ public abstract class JiraAbstractClient extends BaseClient {
|
|||
return (JiraIssue) getResultForObject(JiraIssue.class, responseEntity);
|
||||
}
|
||||
|
||||
public JSONArray getDemands(String projectKey, String issueType, int startAt, int maxResults) {
|
||||
String jql = getBaseUrl() + "/search?jql=project=" + projectKey + "+AND+issuetype=" + issueType
|
||||
+ "&maxResults=" + maxResults + "&startAt=" + startAt + "&fields=summary,issuetype";
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange(jql,
|
||||
HttpMethod.GET, getAuthHttpEntity(), String.class);
|
||||
JSONObject jsonObject = JSONObject.parseObject(responseEntity.getBody());
|
||||
return jsonObject.getJSONArray("issues");
|
||||
}
|
||||
|
||||
public List<JiraField> getFields() {
|
||||
ResponseEntity<String> response = restTemplate.exchange(getBaseUrl() + "/field", HttpMethod.GET, getAuthHttpEntity(), String.class);
|
||||
return (List<JiraField>) getResultForList(JiraField.class, response);
|
||||
|
@ -126,9 +137,10 @@ public abstract class JiraAbstractClient extends BaseClient {
|
|||
PASSWD = config.getPassword();
|
||||
}
|
||||
|
||||
public JiraIssueListResponse getProjectIssues(int startAt, int maxResults, String projectKey) {
|
||||
public JiraIssueListResponse getProjectIssues(int startAt, int maxResults, String projectKey, String issueType) {
|
||||
ResponseEntity<String> responseEntity;
|
||||
responseEntity = restTemplate.exchange(getBaseUrl() + "/search?startAt={1}&maxResults={2}&jql=project={3}", HttpMethod.GET, getAuthHttpEntity(), String.class, startAt, maxResults, projectKey);
|
||||
responseEntity = restTemplate.exchange(getBaseUrl() + "/search?startAt={1}&maxResults={2}&jql=project={3}+AND+issuetype={4}", HttpMethod.GET, getAuthHttpEntity(), String.class,
|
||||
startAt, maxResults, projectKey, issueType);
|
||||
return (JiraIssueListResponse)getResultForObject(JiraIssueListResponse.class, responseEntity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class TapdClient extends BaseClient {
|
|||
public JSONArray getPlatformUser(String projectId) {
|
||||
String url = getBaseUrl() + "/workspaces/users?workspace_id=" + projectId;
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, getAuthHttpEntity(), String.class, projectId);
|
||||
return JSONArray.parseArray(response.getBody());
|
||||
return JSONArray.parseObject(response.getBody()).getJSONArray("data");
|
||||
}
|
||||
|
||||
public void auth() {
|
||||
|
@ -60,21 +60,26 @@ public class TapdClient extends BaseClient {
|
|||
}
|
||||
|
||||
public TapdGetIssueResponse getIssueForPageByIds(String projectId, int pageNum, int limit, List<String> ids) {
|
||||
String url = getBaseUrl() + "/bugs?workspace_id={1}&page={2}&limit={3}&fields={4}";
|
||||
String url = getBaseUrl() + "/bugs?workspace_id={1}&page={2}&limit={3}";
|
||||
StringBuilder idStr = new StringBuilder();
|
||||
if (!CollectionUtils.isEmpty(ids)) {
|
||||
ids.forEach(item -> {
|
||||
idStr.append(item + ",");
|
||||
});
|
||||
url += "&id={5}";
|
||||
url += "&id={4}";
|
||||
}
|
||||
String fields = "id,title,description,priority,severity,reporter,status";
|
||||
LogUtil.info("ids: " + idStr);
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, getAuthHttpEntity(), String.class,
|
||||
projectId, pageNum, limit, fields, idStr);
|
||||
projectId, pageNum, limit, idStr);
|
||||
return (TapdGetIssueResponse) getResultForObject(TapdGetIssueResponse.class, response);
|
||||
}
|
||||
|
||||
public JSONArray getDemands(String projectId) {
|
||||
String url = getBaseUrl() + "/stories?workspace_id={1}";
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, getAuthHttpEntity(), String.class, projectId);
|
||||
return JSONArray.parseObject(response.getBody()).getJSONArray("data");
|
||||
}
|
||||
|
||||
public TapdBug addIssue(MultiValueMap<String, Object> paramMap) {
|
||||
String url = getBaseUrl() + "/bugs";
|
||||
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, getAuthHeader());
|
||||
|
|
|
@ -25,6 +25,10 @@ public abstract class ZentaoClient extends BaseClient {
|
|||
public RequestUrl requestUrl;
|
||||
protected String url;
|
||||
|
||||
public ZentaoClient(String url) {
|
||||
ENDPOINT = url;
|
||||
}
|
||||
|
||||
private static final String BUG_LIST_URL="?m=bug&f=browse&productID={0}&branch=&browseType=¶m=0&orderBy=&pageID={1}&recPerPage={2}&t=json&zentaosid=";
|
||||
|
||||
public String login() {
|
||||
|
|
|
@ -21,6 +21,10 @@ public class ZentaoGetClient extends ZentaoClient {
|
|||
|
||||
RequestUrl request = new RequestUrl();
|
||||
|
||||
public ZentaoGetClient(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
{
|
||||
request.setLogin(getNotSuperModelUrl(LOGIN));
|
||||
request.setSessionGet(getNotSuperModelUrl(SESSION_GET));
|
||||
|
|
|
@ -20,6 +20,10 @@ public class ZentaoPathInfoClient extends ZentaoClient {
|
|||
private static final String REPLACE_IMG_URL = "<img src=\"/zentao/file-read-$1\"/>";
|
||||
private static final Pattern IMG_PATTERN = Pattern.compile("file-read-(.*?)\"/>");
|
||||
|
||||
public ZentaoPathInfoClient(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
protected RequestUrl request = new RequestUrl();
|
||||
|
||||
{
|
||||
|
|
|
@ -42,13 +42,6 @@ public class TestCaseIssueService {
|
|||
public void delTestCaseIssues(String testCaseId) {
|
||||
TestCaseIssuesExample example = new TestCaseIssuesExample();
|
||||
example.createCriteria().andTestCaseIdEqualTo(testCaseId);
|
||||
List<TestCaseIssues> testCaseIssues = testCaseIssuesMapper.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(testCaseIssues)) {
|
||||
List<String> list = testCaseIssues.stream().map(TestCaseIssues::getIssuesId).collect(Collectors.toList());
|
||||
list.forEach(id -> {
|
||||
issuesMapper.deleteByPrimaryKey(id);
|
||||
});
|
||||
}
|
||||
testCaseIssuesMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b90efefd1312b35dea5c2c1fb3a7f78904a7bcd7
|
||||
Subproject commit 33d1b2a4d29059882f026cb3f70653fca18381e4
|
Loading…
Reference in New Issue