From e7e626a1afd6f40ef14b26e4dc5aed5ee7959adc Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Tue, 1 Nov 2022 10:45:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20MS?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E5=90=8C=E6=AD=A5=E8=87=B3Azure=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1017812 --user=宋昌昌 【接口测试】github#18391,Azure Devops 平台创建缺陷,上传附件未同步上传到缺陷平台里 https://www.tapd.cn/55049933/s/1284499 --- .../service/AttachmentService.java | 7 ++++- .../io/metersphere/service/IssuesService.java | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java b/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java index 3cf4d206fa..8da7bfa73d 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java @@ -100,6 +100,7 @@ public class AttachmentService { File uploadFile = new File(fileAttachmentMetadata.getFilePath() + "/" + fileAttachmentMetadata.getName()); IssuesRequest issuesRequest = new IssuesRequest(); issuesRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); Objects.requireNonNull(IssueFactory.createPlatform(issues.getPlatform(), issuesRequest)) .syncIssuesAttachment(updateRequest, uploadFile, AttachmentSyncType.UPLOAD); } @@ -120,6 +121,7 @@ public class AttachmentService { File deleteFile = new File(fileAttachmentMetadata.getFilePath() + "/" + fileAttachmentMetadata.getName()); IssuesRequest issuesRequest = new IssuesRequest(); issuesRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); Objects.requireNonNull(IssueFactory.createPlatform(issues.getPlatform(), issuesRequest)) .syncIssuesAttachment(updateRequest, deleteFile, AttachmentSyncType.DELETE); } @@ -178,6 +180,7 @@ public class AttachmentService { File refFile = downloadMetadataFile(metadataRefId, fileMetadata.getName()); IssuesRequest issuesRequest = new IssuesRequest(); issuesRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); Objects.requireNonNull(IssueFactory.createPlatform(issues.getPlatform(), issuesRequest)) .syncIssuesAttachment(updateRequest, refFile, AttachmentSyncType.UPLOAD); FileUtils.deleteFile(FileUtils.ATTACHMENT_TMP_DIR + File.separator + fileMetadata.getName()); @@ -275,6 +278,7 @@ public class AttachmentService { File refFile = downloadMetadataFile(metadataRefId, fileMetadata.getName()); IssuesRequest issuesRequest = new IssuesRequest(); issuesRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); Objects.requireNonNull(IssueFactory.createPlatform(issues.getPlatform(), issuesRequest)) .syncIssuesAttachment(updateRequest, refFile, AttachmentSyncType.UPLOAD); FileUtils.deleteFile(FileUtils.ATTACHMENT_TMP_DIR + File.separator + fileMetadata.getName()); @@ -299,6 +303,7 @@ public class AttachmentService { File deleteFile = new File(FileUtils.ATTACHMENT_TMP_DIR + File.separator + fileAttachmentMetadata.getName()); IssuesRequest issuesRequest = new IssuesRequest(); issuesRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); Objects.requireNonNull(IssueFactory.createPlatform(issues.getPlatform(), issuesRequest)) .syncIssuesAttachment(updateRequest, deleteFile, AttachmentSyncType.DELETE); }); @@ -326,7 +331,7 @@ public class AttachmentService { List attachmentModuleRelations = attachmentModuleRelationMapper.selectByExample(example); List attachmentIds = attachmentModuleRelations.stream().map(AttachmentModuleRelation::getAttachmentId) .collect(Collectors.toList()); - return attachmentIds; + return attachmentIds; } public String getRefIdByAttachmentId(String attachmentId) { diff --git a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java index 116a534c84..0a296a0fc5 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java @@ -143,12 +143,21 @@ public class IssuesService { customFieldIssuesService.addFields(issuesRequest.getId(), issuesRequest.getAddFields()); customFieldIssuesService.editFields(issuesRequest.getId(), issuesRequest.getEditFields()); if (StringUtils.isNotEmpty(issuesRequest.getCopyIssueId())) { + final String platformId = issues.getPlatformId(); // 复制新增, 同步缺陷的MS附件 AttachmentRequest attachmentRequest = new AttachmentRequest(); attachmentRequest.setCopyBelongId(issuesRequest.getCopyIssueId()); attachmentRequest.setBelongId(issues.getId()); attachmentRequest.setBelongType(AttachmentType.ISSUE.type()); attachmentService.copyAttachment(attachmentRequest); + + // MS附件同步到其他平台, Jira, Zentao已经在创建缺陷时处理, AzureDevops单独处理 + if (StringUtils.equals(issuesRequest.getPlatform(), IssuesManagePlatform.AzureDevops.toString())) { + AttachmentRequest request = new AttachmentRequest(); + request.setBelongId(issuesRequest.getCopyIssueId()); + request.setBelongType(AttachmentType.ISSUE.type()); + uploadAzureCopyAttachment(request, issuesRequest.getPlatform(), platformId); + } } else { final String issueId = issues.getId(); final String platform = issues.getPlatform(); @@ -194,6 +203,7 @@ public class IssuesService { File refFile = attachmentService.downloadMetadataFile(filemetaId, fileMetadata.getName()); IssuesRequest addIssueRequest = new IssuesRequest(); addIssueRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + addIssueRequest.setProjectId(SessionUtils.getCurrentProjectId()); Objects.requireNonNull(IssueFactory.createPlatform(platform, addIssueRequest)) .syncIssuesAttachment(issuesRequest, refFile, AttachmentSyncType.UPLOAD); FileUtils.deleteFile(FileUtils.ATTACHMENT_TMP_DIR + File.separator + fileMetadata.getName()); @@ -1107,4 +1117,21 @@ public class IssuesService { }).collect(Collectors.toList()); return filterIssues; } + + private void uploadAzureCopyAttachment(AttachmentRequest attachmentRequest, String platform, String platformId) { + List attachmentIds = attachmentService.getAttachmentIdsByParam(attachmentRequest); + if (CollectionUtils.isNotEmpty(attachmentIds)) { + attachmentIds.forEach(attachmentId -> { + FileAttachmentMetadata fileAttachmentMetadata = attachmentService.getFileAttachmentMetadataByFileId(attachmentId); + File file = new File(fileAttachmentMetadata.getFilePath() + "/" + fileAttachmentMetadata.getName()); + IssuesRequest createRequest = new IssuesRequest(); + createRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + createRequest.setProjectId(SessionUtils.getCurrentProjectId()); + IssuesPlatform azurePlatform = Objects.requireNonNull(IssueFactory.createPlatform(platform, createRequest)); + IssuesUpdateRequest uploadRequest = new IssuesUpdateRequest(); + uploadRequest.setPlatformId(platformId); + azurePlatform.syncIssuesAttachment(uploadRequest, file, AttachmentSyncType.UPLOAD); + }); + } + } }