From ac0202e4464e9e359c3ef4249d41de0e9372f2be Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 31 May 2022 15:05:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20jira=E6=94=AF=E6=8C=81=E7=BC=96=E8=BE=91=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1011036 --user=陈建星 【测试跟踪】github##11078,不能在ms上修改jira缺陷的“平台状态” https://www.tapd.cn/55049933/s/1169579 --- .../track/controller/IssuesController.java | 6 +++ .../metersphere/track/issue/JiraPlatform.java | 12 +++++ .../issue/client/JiraAbstractClient.java | 24 +++++++++ .../domain/jira/JiraTransitionsResponse.java | 50 +++++++++++++++++++ .../request/testcase/IssuesUpdateRequest.java | 3 ++ .../track/service/IssuesService.java | 12 +++++ .../track/issue/IssueEditDetail.vue | 37 ++++++++++++-- frontend/src/network/Issue.js | 10 +++- 8 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/track/issue/domain/jira/JiraTransitionsResponse.java diff --git a/backend/src/main/java/io/metersphere/track/controller/IssuesController.java b/backend/src/main/java/io/metersphere/track/controller/IssuesController.java index 2636faed83..60247d7777 100644 --- a/backend/src/main/java/io/metersphere/track/controller/IssuesController.java +++ b/backend/src/main/java/io/metersphere/track/controller/IssuesController.java @@ -17,6 +17,7 @@ import io.metersphere.notice.annotation.SendNotice; import io.metersphere.track.dto.DemandDTO; import io.metersphere.track.issue.domain.PlatformUser; import io.metersphere.track.issue.domain.jira.JiraIssueType; +import io.metersphere.track.issue.domain.jira.JiraTransitionsResponse; import io.metersphere.track.issue.domain.zentao.ZentaoBuild; import io.metersphere.track.request.issues.JiraIssueTypeRequest; import io.metersphere.track.request.testcase.AuthUserIssueRequest; @@ -170,6 +171,11 @@ public class IssuesController { return issuesService.getIssueTypes(request); } + @PostMapping("/jira/transitions") + public List getJiraTransitions(@RequestBody JiraIssueTypeRequest request) { + return issuesService.getJiraTransitions(request); + } + @GetMapping("/demand/list/{projectId}") public List getDemandList(@PathVariable String projectId) { return issuesService.getDemandList(projectId); diff --git a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java index 052fe6e3cd..c8a6754846 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -446,6 +446,14 @@ public class JiraPlatform extends AbstractIssuePlatform { // 上传新附件 imageFiles.forEach(img -> jiraClientV2.uploadAttachment(request.getPlatformId(), img)); + if (request.getTransitions() != null) { + try { + jiraClientV2.setTransitions(request.getPlatformId(), request.getTransitions()); + } catch (Exception e) { + LogUtil.error(e); + } + } + handleIssueUpdate(request); } @@ -529,6 +537,10 @@ public class JiraPlatform extends AbstractIssuePlatform { return setUserConfig(getUserPlatInfo(this.workspaceId)); } + public List getTransitions(String issueKey) { + return jiraClientV2.getTransitions(issueKey); + } + public IssueTemplateDao getThirdPartTemplate() { setUserConfig(); Set ignoreSet = new HashSet() {{ diff --git a/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java b/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java index f959de72b8..1450bad7a5 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java @@ -127,6 +127,11 @@ public abstract class JiraAbstractClient extends BaseClient { return (JiraAddIssueResponse) getResultForObject(JiraAddIssueResponse.class, response); } + public List getTransitions(String issueKey) { + ResponseEntity response = restTemplate.exchange(getBaseUrl() + "/issue/{1}/transitions", HttpMethod.GET, getAuthHttpEntity(), String.class, issueKey); + return ((JiraTransitionsResponse) getResultForObject(JiraTransitionsResponse.class, response)).getTransitions(); + } + public void updateIssue(String id, String body) { LogUtil.info("addIssue: " + body); HttpHeaders headers = getAuthHeader(); @@ -209,6 +214,12 @@ public abstract class JiraAbstractClient extends BaseClient { return getBasicHttpHeaders(USER_NAME, PASSWD); } + protected HttpHeaders getAuthJsonHeader() { + HttpHeaders headers = getAuthHeader(); + headers.setContentType(MediaType.APPLICATION_JSON); + return headers; + } + protected String getBaseUrl() { return ENDPOINT + PREFIX; } @@ -237,4 +248,17 @@ public abstract class JiraAbstractClient extends BaseClient { HttpMethod.GET, getAuthHttpEntity(), String.class, startAt, maxResults, projectKey, issueType); return (JiraIssueListResponse)getResultForObject(JiraIssueListResponse.class, responseEntity); } + + public void setTransitions(String jiraKey, JiraTransitionsResponse.Transitions transitions) { + LogUtil.info("setTransitions: " + transitions); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("transition", transitions); + HttpEntity requestEntity = new HttpEntity<>(jsonObject.toJSONString(), getAuthJsonHeader()); + try { + restTemplate.exchange(getBaseUrl() + "/issue/{1}/transitions", HttpMethod.POST, requestEntity, String.class, jiraKey); + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); + MSException.throwException(e.getMessage()); + } + } } diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/jira/JiraTransitionsResponse.java b/backend/src/main/java/io/metersphere/track/issue/domain/jira/JiraTransitionsResponse.java new file mode 100644 index 0000000000..e767d07c9a --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/issue/domain/jira/JiraTransitionsResponse.java @@ -0,0 +1,50 @@ +package io.metersphere.track.issue.domain.jira; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +public class JiraTransitionsResponse { + + private String expand; + private List transitions; + + @Getter + @Setter + public static class Transitions { + private String id; + private String name; + private To to; + private Boolean hasScreen; + private Boolean isGlobal; + private Boolean isInitial; + private Boolean isAvailable; + private Boolean isConditional; + private Boolean isLooped; + + } + + @Getter + @Setter + public static class To { + private String self; + private String description; + private String iconUrl; + private String name; + private String id; + private StatusCategory statusCategory; + } + + @Getter + @Setter + public static class StatusCategory { + private String self; + private int id; + private String key; + private String colorName; + private String name; + } +} diff --git a/backend/src/main/java/io/metersphere/track/request/testcase/IssuesUpdateRequest.java b/backend/src/main/java/io/metersphere/track/request/testcase/IssuesUpdateRequest.java index 02b54bf38b..7ce69cc55b 100644 --- a/backend/src/main/java/io/metersphere/track/request/testcase/IssuesUpdateRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testcase/IssuesUpdateRequest.java @@ -1,6 +1,7 @@ package io.metersphere.track.request.testcase; import io.metersphere.base.domain.IssuesWithBLOBs; +import io.metersphere.track.issue.domain.jira.JiraTransitionsResponse; import lombok.Getter; import lombok.Setter; @@ -34,4 +35,6 @@ public class IssuesUpdateRequest extends IssuesWithBLOBs { * azure devops bug同步fields */ private String devopsFields; + + private JiraTransitionsResponse.Transitions transitions; } diff --git a/backend/src/main/java/io/metersphere/track/service/IssuesService.java b/backend/src/main/java/io/metersphere/track/service/IssuesService.java index 0375abc3fc..5ec5e8c4d8 100644 --- a/backend/src/main/java/io/metersphere/track/service/IssuesService.java +++ b/backend/src/main/java/io/metersphere/track/service/IssuesService.java @@ -29,6 +29,7 @@ import io.metersphere.track.dto.*; import io.metersphere.track.issue.*; import io.metersphere.track.issue.domain.PlatformUser; import io.metersphere.track.issue.domain.jira.JiraIssueType; +import io.metersphere.track.issue.domain.jira.JiraTransitionsResponse; import io.metersphere.track.issue.domain.zentao.ZentaoBuild; import io.metersphere.track.request.issues.JiraIssueTypeRequest; import io.metersphere.track.request.testcase.AuthUserIssueRequest; @@ -755,4 +756,15 @@ public class IssuesService { request.setOrders(ServiceUtils.getDefaultOrderByField(request.getOrders(), "create_time")); return extIssuesMapper.getIssues(request); } + + public List getJiraTransitions(JiraIssueTypeRequest request) { + IssuesRequest issuesRequest = getDefaultIssueRequest(request.getProjectId(), request.getWorkspaceId()); + JiraPlatform platform = (JiraPlatform) IssueFactory.createPlatform(IssuesManagePlatform.Jira.toString(), issuesRequest); + try { + return platform.getTransitions(request.getJiraKey()); + } catch (Exception e) { + LogUtil.error(e); + } + return new ArrayList<>(); + } } diff --git a/frontend/src/business/components/track/issue/IssueEditDetail.vue b/frontend/src/business/components/track/issue/IssueEditDetail.vue index 5187f19dbb..c952cf56a5 100644 --- a/frontend/src/business/components/track/issue/IssueEditDetail.vue +++ b/frontend/src/business/components/track/issue/IssueEditDetail.vue @@ -32,6 +32,19 @@ + + + + + + + + + + @@ -118,11 +131,12 @@ import CustomFiledComponent from "@/business/components/project/template/CustomF import TestCaseIssueList from "@/business/components/track/issue/TestCaseIssueList"; import IssueEditDetail from "@/business/components/track/issue/IssueEditDetail"; import {getCurrentProjectID, getCurrentUser, getCurrentUserId, getCurrentWorkspaceId,} from "@/common/js/utils"; -import {enableThirdPartTemplate, getIssuePartTemplateWithProject, getIssuesListById} from "@/network/Issue"; +import {enableThirdPartTemplate, getIssuePartTemplateWithProject, getJiraTransitions} from "@/network/Issue"; import CustomFiledFormItem from "@/business/components/common/components/form/CustomFiledFormItem"; import MsMarkDownText from "@/business/components/track/case/components/MsMarkDownText"; import IssueComment from "@/business/components/track/issue/IssueComment"; import ReviewCommentItem from "@/business/components/track/review/commom/ReviewCommentItem"; +import {JIRA} from "@/common/js/constants"; const {getIssuesById} = require("@/network/Issue"); @@ -172,13 +186,15 @@ export default { remark: null, tapdUsers:[], zentaoBuilds:[], - zentaoAssigned: '' + zentaoAssigned: '', + platformStatus: null }, tapdUsers: [], zentaoUsers: [], Builds: [], hasTapdId: false, hasZentaoId: false, + jiraTransitions: null, currentProject: null, toolbars: { bold: false, // 粗体 @@ -277,12 +293,13 @@ export default { }, init(template, data) { this.issueTemplate = template; - this.getThirdPartyInfo(); this.initEdit(data); + this.getThirdPartyInfo(); this.result.loading = false; }, getThirdPartyInfo() { let platform = this.issueTemplate.platform; + this.jiraTransitions = null; if (platform === 'Zentao') { this.hasZentaoId = true; this.result = this.$post("/issues/zentao/builds", { @@ -299,8 +316,7 @@ export default { this.zentaoUsers = response.data; }); }); - } - if (platform === 'Tapd') { + } else if (platform === 'Tapd') { this.hasTapdId = true; this.result = this.$post("/issues/tapd/user", { projectId: this.projectId, @@ -308,6 +324,10 @@ export default { }, (response) => { this.tapdUsers = response.data; }); + } else if (JIRA === platform && this.form.id) { + getJiraTransitions(this.form.platformId, (data) => { + this.jiraTransitions = data; + }); } }, initEdit(data) { @@ -369,6 +389,13 @@ export default { Object.assign(param, this.form); param.projectId = this.projectId; param.workspaceId = getCurrentWorkspaceId(); + if (this.jiraTransitions) { + this.jiraTransitions.forEach(item => { + if (item.to.name === this.form.platformStatus) { + param.transitions = item; + } + }); + } buildCustomFields(this.form, param, this.issueTemplate); if (this.planId) { // 测试计划用例创建缺陷 diff --git a/frontend/src/network/Issue.js b/frontend/src/network/Issue.js index c6f19ba134..3aed654011 100644 --- a/frontend/src/network/Issue.js +++ b/frontend/src/network/Issue.js @@ -1,6 +1,6 @@ import {post, get} from "@/common/js/ajax"; import {getPageDate} from "@/common/js/tableUtils"; -import {getCurrentProjectID, hasLicense} from "@/common/js/utils"; +import {getCurrentProjectID, getCurrentWorkspaceId, hasLicense} from "@/common/js/utils"; import {baseGet, basePost} from "@/network/base-network"; import {getCurrentProject} from "@/network/project"; import {JIRA, LOCAL} from "@/common/js/constants"; @@ -163,3 +163,11 @@ export function isThirdPartEnable(callback) { export function getJiraIssueType(param, callback) { return basePost('/issues/jira/issuetype', param, callback); } + +export function getJiraTransitions(jiraKey, callback) { + return basePost('/issues/jira/transitions', { + jiraKey, + projectId: getCurrentProjectID(), + workspaceId: getCurrentWorkspaceId() + }, callback); +}