feat(测试跟踪): 测试用例可关联JIRA需求

This commit is contained in:
shiziyuan9527 2021-03-20 20:32:14 +08:00
parent 787909a415
commit f3eb82c839
6 changed files with 71 additions and 4 deletions

View File

@ -1,6 +1,7 @@
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.commons.constants.IssuesManagePlatform;
@ -81,7 +82,55 @@ public class JiraPlatform extends AbstractIssuePlatform {
@Override
public List<DemandDTO> getDemandList(String projectId) {
return null;
List<DemandDTO> list = new ArrayList<>();
try {
String key = this.getProjectId(projectId);
if (StringUtils.isBlank(key)) {
MSException.throwException("未关联Jira 项目Key");
}
String config = getPlatformConfig(IssuesManagePlatform.Jira.toString());
JSONObject object = JSON.parseObject(config);
if (object == null) {
MSException.throwException("jira config is null");
}
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;
responseEntity = restTemplate.exchange(url + "/rest/api/2/search?jql=project="+key+"+AND+issuetype="+type+"&fields=summary,issuetype",
HttpMethod.GET, requestEntity, String.class);
String body = responseEntity.getBody();
JSONObject jsonObject = JSONObject.parseObject(body);
JSONArray jsonArray = jsonObject.getJSONArray("issues");
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);
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
MSException.throwException("调用Jira查询需求失败");
}
return list;
}
@Override

View File

@ -16,6 +16,9 @@
<el-form-item :label="$t('organization.integration.jira_issuetype')" prop="issuetype">
<el-input v-model="form.issuetype" :placeholder="$t('organization.integration.input_jira_issuetype')"/>
</el-form-item>
<el-form-item :label="$t('organization.integration.jira_storytype')" prop="storytype">
<el-input v-model="form.storytype" :placeholder="$t('organization.integration.input_jira_storytype')"/>
</el-form-item>
</el-form>
</div>
@ -79,6 +82,11 @@ export default {
required: true,
message: this.$t('organization.integration.input_jira_issuetype'),
trigger: ['change', 'blur']
},
storytype: {
required: true,
message: this.$t('organization.integration.input_jira_storytype'),
trigger: ['change', 'blur']
}
},
}
@ -97,6 +105,7 @@ export default {
this.$set(this.form, 'password', config.password);
this.$set(this.form, 'url', config.url);
this.$set(this.form, 'issuetype', config.issuetype);
this.$set(this.form, 'storytype', config.storytype);
} else {
this.clear();
}
@ -114,7 +123,8 @@ export default {
account: this.form.account,
password: this.form.password,
url: formatUrl,
issuetype: this.form.issuetype
issuetype: this.form.issuetype,
storytype: this.form.storytype
};
const {lastOrganizationId} = getCurrentUser();
param.organizationId = lastOrganizationId;
@ -139,6 +149,7 @@ export default {
this.$set(this.form, 'password', '');
this.$set(this.form, 'url', '');
this.$set(this.form, 'issuetype', '');
this.$set(this.form, 'storytype', '');
this.$nextTick(() => {
this.$refs.form.clearValidate();
});

View File

@ -775,6 +775,7 @@ export default {
this.demandOptions.unshift({id: 'other', name: this.$t('test_track.case.other'), platform: 'Other'})
this.result = {loading : false};
}).catch(() => {
this.demandOptions.unshift({id: 'other', name: this.$t('test_track.case.other'), platform: 'Other'})
this.result = {loading : false};
})
}

View File

@ -314,11 +314,13 @@ export default {
account: 'Account',
password: 'Password',
jira_url: 'JIRA url',
jira_issuetype: 'JIRA issuetype',
jira_issuetype: 'JIRA issue type',
jira_storytype: 'JIRA story type',
input_api_account: 'please enter account',
input_api_password: 'Please enter password',
input_jira_url: 'Please enter Jira address, for example: https://metersphere.atlassian.net/',
input_jira_issuetype: 'Please enter the question type',
input_jira_issuetype: 'Please enter the issue type',
input_jira_storytype: 'Please enter the story type',
zentao_url: 'Zentao url',
input_zentao_url: 'Please enter Zentao address, for example: http://xx.xx.xx.xx/zentao/',
use_tip: 'Usage guidelines:',

View File

@ -313,10 +313,12 @@ export default {
password: '密码',
jira_url: 'JIRA 地址',
jira_issuetype: '问题类型',
jira_storytype: '需求类型',
input_api_account: '请输入账号',
input_api_password: '请输入密码',
input_jira_url: '请输入Jira地址https://metersphere.atlassian.net/',
input_jira_issuetype: '请输入问题类型',
input_jira_storytype: '请输入需求类型',
zentao_url: 'Zentao 地址',
input_zentao_url: '请输入Zentao地址http://xx.xx.xx.xx/zentao/',
use_tip: '使用指引:',

View File

@ -313,10 +313,12 @@ export default {
password: '密碼',
jira_url: 'JIRA 地址',
jira_issuetype: '問題類型',
jira_storytype: '需求類型',
input_api_account: '請輸入賬號',
input_api_password: '請輸入密碼',
input_jira_url: '請輸入Jira地址https://metersphere.atlassian.net/',
input_jira_issuetype: '請輸入問題類型',
input_jira_storytype: '請輸入需求類型',
zentao_url: 'Zentao 地址',
input_zentao_url: '請輸入Zentao地址http://xx.xx.xx.xx/zentao/',
use_tip: '使用指引:',