fix(接口测试): 修复jenkins执行测试计划会发送多个通知的问题

--bug=1013358 --user=宋天阳 【消息通知】用jenkins 跑一个包含100+
场景的测试计划,邮箱收到100+条通知,建议只接收执行该测试计划的一个通知
https://www.tapd.cn/55049933/s/1174780
This commit is contained in:
song-tianyang 2022-06-07 13:49:54 +08:00 committed by f2c-ci-robot[bot]
parent ad4b57a5cc
commit 144de4b950
2 changed files with 16 additions and 4 deletions

View File

@ -33,6 +33,7 @@ import io.metersphere.track.dto.PlanReportCaseDTO;
import io.metersphere.utils.LoggerUtil; import io.metersphere.utils.LoggerUtil;
import org.apache.commons.beanutils.BeanMap; import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -162,6 +163,7 @@ public class ApiScenarioReportService {
} }
public List<APIScenarioReportResult> list(QueryAPIReportRequest request) { public List<APIScenarioReportResult> list(QueryAPIReportRequest request) {
request = this.initRequest(request);
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
List<APIScenarioReportResult> list = extApiScenarioReportMapper.list(request); List<APIScenarioReportResult> list = extApiScenarioReportMapper.list(request);
List<String> userIds = list.stream().map(APIScenarioReportResult::getUserId) List<String> userIds = list.stream().map(APIScenarioReportResult::getUserId)
@ -175,7 +177,20 @@ public class ApiScenarioReportService {
return list; return list;
} }
public QueryAPIReportRequest initRequest(QueryAPIReportRequest request){
if(request != null){
//初始化triggerMode的查询条件 如果查询API的话增加 JENKINS_RUN_TEST_PLAN(jenkins调用测试计划时执行的场景) 查询条件
if(MapUtils.isNotEmpty(request.getFilters()) && request.getFilters().containsKey("trigger_mode")
&& CollectionUtils.isNotEmpty(request.getFilters().get("trigger_mode"))
&& request.getFilters().get("trigger_mode").contains("API") && !request.getFilters().get("trigger_mode").contains(ReportTriggerMode.JENKINS_RUN_TEST_PLAN.name())){
request.getFilters().get("trigger_mode").add(ReportTriggerMode.JENKINS_RUN_TEST_PLAN.name());
}
}
return request;
}
public List<String> idList(QueryAPIReportRequest request) { public List<String> idList(QueryAPIReportRequest request) {
request = this.initRequest(request);
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
return extApiScenarioReportMapper.idList(request); return extApiScenarioReportMapper.idList(request);
} }
@ -224,10 +239,6 @@ public class ApiScenarioReportService {
if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) { if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) {
return report; return report;
} }
if(StringUtils.equalsAnyIgnoreCase(report.getTriggerMode(),ReportTriggerMode.JENKINS_RUN_TEST_PLAN.name())){
//jenkins运行测试计划时执行的场景触发方式改回API
report.setTriggerMode(ReportTriggerMode.API.name());
}
if (runMode.equals("CASE")) { if (runMode.equals("CASE")) {
report.setTriggerMode(TriggerMode.MANUAL.name()); report.setTriggerMode(TriggerMode.MANUAL.name());
} }

View File

@ -5,6 +5,7 @@
<span v-if="triggerMode === 'TEST_PLAN_SCHEDULE'">{{$t('commons.trigger_mode.test_plan_schedule')}}</span> <span v-if="triggerMode === 'TEST_PLAN_SCHEDULE'">{{$t('commons.trigger_mode.test_plan_schedule')}}</span>
<span v-if="triggerMode === 'TEST_PLAN_API'">{{$t('commons.trigger_mode.test_plan_api')}}</span> <span v-if="triggerMode === 'TEST_PLAN_API'">{{$t('commons.trigger_mode.test_plan_api')}}</span>
<span v-if="triggerMode === 'API'">{{$t('commons.trigger_mode.api')}}</span> <span v-if="triggerMode === 'API'">{{$t('commons.trigger_mode.api')}}</span>
<span v-if="triggerMode === 'JENKINS_RUN_TEST_PLAN'">{{$t('commons.trigger_mode.api')}}</span>
<span v-if="triggerMode === 'BATCH'">{{$t('api_test.automation.batch_execute')}}</span> <span v-if="triggerMode === 'BATCH'">{{$t('api_test.automation.batch_execute')}}</span>
</span> </span>