fix(测试跟踪): 同步jira图片失败

--bug=1013769 --user=陈建星 【测试跟踪】github#13768,项目MS创建缺陷中含有图片-点击同步缺陷到JIRA-MS缺陷中的图片消失-JIRA中的图片还在 https://www.tapd.cn/55049933/s/1172335
This commit is contained in:
chenjianxing 2022-06-05 16:28:43 +08:00 committed by jianxing
parent 08e6bb223d
commit 51acb89783
2 changed files with 22 additions and 5 deletions

View File

@ -75,6 +75,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
String status = getStatus(fields); String status = getStatus(fields);
String description = dealWithDescription(fields.getString("description"), fields.getJSONArray("attachment")); String description = dealWithDescription(fields.getString("description"), fields.getJSONArray("attachment"));
fields.put("description", description);
JSONObject assignee = (JSONObject) fields.get("assignee"); JSONObject assignee = (JSONObject) fields.get("assignee");
issue.setTitle(fields.getString("summary")); issue.setTitle(fields.getString("summary"));
@ -100,7 +101,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
JSONObject attachment = attachments.getJSONObject(i); JSONObject attachment = attachments.getJSONObject(i);
String filename = attachment.getString("filename"); String filename = attachment.getString("filename");
String content = attachment.getString("content"); String content = attachment.getString("content");
if (StringUtils.equals(attachment.getString("mimeType"), "image/jpeg")) { if (StringUtils.contains(attachment.getString("mimeType"), "image")) {
String contentUrl = "![" + filename + "](" + content + ")"; String contentUrl = "![" + filename + "](" + content + ")";
fileContentMap.put(filename, contentUrl); fileContentMap.put(filename, contentUrl);
} else { } else {
@ -117,6 +118,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
List<String> keys = fileContentMap.keySet().stream().filter(key -> splitStr.contains(key)).collect(Collectors.toList()); List<String> keys = fileContentMap.keySet().stream().filter(key -> splitStr.contains(key)).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(keys)) { if (CollectionUtils.isNotEmpty(keys)) {
description = description.replace(splitStr, fileContentMap.get(keys.get(0))); description = description.replace(splitStr, fileContentMap.get(keys.get(0)));
fileContentMap.remove(keys.get(0));
} else { } else {
if (splitStr.contains("MS附件")) { if (splitStr.contains("MS附件")) {
// 解析标签内容 // 解析标签内容
@ -130,6 +132,10 @@ public class JiraPlatform extends AbstractIssuePlatform {
} }
} }
for (String key: fileContentMap.keySet()) {
// 同步jira上传的附件
description += "\n" + fileContentMap.get(key);
}
return description; return description;
} }
@ -215,15 +221,14 @@ public class JiraPlatform extends AbstractIssuePlatform {
} }
private List<File> getImageFiles(IssuesUpdateRequest issuesRequest) { private List<File> getImageFiles(IssuesUpdateRequest issuesRequest) {
List<File> files = getImageFiles(issuesRequest.getDescription()); List<File> files = new ArrayList<>();
List<CustomFieldItemDTO> customFields = CustomFieldService.getCustomFields(issuesRequest.getCustomFields()); List<CustomFieldItemDTO> customFields = CustomFieldService.getCustomFields(issuesRequest.getCustomFields());
customFields.forEach(item -> { customFields.forEach(item -> {
String fieldName = item.getCustomData(); String fieldName = item.getCustomData();
if (StringUtils.isNotBlank(fieldName)) { if (StringUtils.isNotBlank(fieldName)) {
if (item.getValue() != null) { if (item.getValue() != null) {
if (StringUtils.isNotBlank(item.getType())) { if (StringUtils.isNotBlank(item.getType())) {
if (StringUtils.equalsAny(item.getType(), "richText") if (StringUtils.equalsAny(item.getType(), "richText")) {
&& !item.getId().equals("description")) {
files.addAll(getImageFiles(item.getValue().toString())); files.addAll(getImageFiles(item.getValue().toString()));
} }
} }

View File

@ -243,12 +243,24 @@ public abstract class JiraAbstractClient extends BaseClient {
} }
public JiraIssueListResponse getProjectIssues(int startAt, int maxResults, String projectKey, String issueType) { public JiraIssueListResponse getProjectIssues(int startAt, int maxResults, String projectKey, String issueType) {
return getProjectIssues(startAt, maxResults, projectKey, issueType, null);
}
public JiraIssueListResponse getProjectIssues(int startAt, int maxResults, String projectKey, String issueType, String fields) {
ResponseEntity<String> responseEntity; ResponseEntity<String> responseEntity;
responseEntity = restTemplate.exchange(getBaseUrl() + "/search?startAt={1}&maxResults={2}&jql=project={3}+AND+issuetype={4}", String url = getBaseUrl() + "/search?startAt={1}&maxResults={2}&jql=project={3}+AND+issuetype={4}";
if (StringUtils.isNotBlank(fields)) {
url = url + "&fields=" + fields;
}
responseEntity = restTemplate.exchange(url,
HttpMethod.GET, getAuthHttpEntity(), String.class, startAt, maxResults, projectKey, issueType); HttpMethod.GET, getAuthHttpEntity(), String.class, startAt, maxResults, projectKey, issueType);
return (JiraIssueListResponse)getResultForObject(JiraIssueListResponse.class, responseEntity); return (JiraIssueListResponse)getResultForObject(JiraIssueListResponse.class, responseEntity);
} }
public JiraIssueListResponse getProjectIssuesAttachment(int startAt, int maxResults, String projectKey, String issueType) {
return getProjectIssues(startAt, maxResults, projectKey, issueType, "attachment");
}
public void setTransitions(String jiraKey, JiraTransitionsResponse.Transitions transitions) { public void setTransitions(String jiraKey, JiraTransitionsResponse.Transitions transitions) {
LogUtil.info("setTransitions: " + transitions); LogUtil.info("setTransitions: " + transitions);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();